Does Nuxt/Nitro resend Requests?

Hej, I have experienced a flood of request in the Nuxt Application at Work and need some help/input on what the issue might be, where to investigate further. The situation The company I work for, has an Nuxt Application (Nuxt v. 3.13.2), which uses an reverse Proxy to communicate with some Backend Services. In the end of January, we experienced a situation, where a Backend Service recevied 170 times the same POST Request in 7 ms. 32 Requests were answered with 200 and the 138 with 500 (is a valid error and has been fixed). Here is a diagram which suppose to help to understand the setup. Due to the logging Middleware, I see that those 170 Request passed the Nitro Server. Questions Is it possible, that the Nuxt Application resends the Request due to the 500 Response at some point? Might it be possible, that the Nitro Server causes the requests? Can I add logging in Nuxt, to see, if the Requests are coming from the Client?
No description
2 Replies
kapa.ai
kapa.ai3d ago
Hi @L4res | Pascal. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the knowledge sources, I can address some aspects of your question about Nuxt/Nitro resending requests. However, the exact scenario you're describing isn't directly covered in the available documents. 1. Resending requests due to 500 responses: Nuxt and Nitro don't automatically resend requests due to 500 errors by default. However, there are some situations where retries might occur: - The useFetch composable has a retry option that can be set to retry failed requests. As mentioned in the Stack Overflow post about useFetch, you can set retry and retryStatusCodes options to control this behavior. 2. Nitro Server causing requests: There's no direct evidence in the provided sources that Nitro Server would cause multiple requests on its own. However, it's worth noting that Nitro has various hooks that can interact with requests and responses. The Nitro App Hooks documentation shows hooks like request, beforeResponse, and afterResponse that could potentially influence request behavior. 3. Adding logging to see if requests are coming from the client: Yes, you can add logging in Nuxt to track requests. Here are a couple of approaches: a. Use the useRequestEvent composable: As mentioned in the useRequestEvent documentation, you can access the incoming request event:
const event = useRequestEvent()
const url = event?.path
// Log the url or other request details
const event = useRequestEvent()
const url = event?.path
// Log the url or other request details
b. Use Nuxt's built-in logging system: The Nuxt logging documentation shows how to use the logger:
import { defineNuxtModule, useLogger } from '@nuxt/kit'
export default defineNuxtModule({
setup(options, nuxt) {
const logger = useLogger('my-module')
logger.info('Request received:', requestDetails)
}
})
import { defineNuxtModule, useLogger } from '@nuxt/kit'
export default defineNuxtModule({
setup(options, nuxt) {
const logger = useLogger('my-module')
logger.info('Request received:', requestDetails)
}
})
c. Use Nitro hooks: You can use the request hook from Nitro to log incoming requests:
nitro.hooks.hook('request', (event) => {
console.log('Request received:', event.path)
})
nitro.hooks.hook('request', (event) => {
console.log('Request received:', event.path)
})
It's important to note that the scenario you're describing (170 requests in 7ms) seems unusual and might indicate an issue beyond normal Nuxt/Nitro behavior. It could be worth investigating other factors such as load balancers, network issues, or client-side code that might be triggering multiple requests. For a more detailed investigation, you might want to implement comprehensive logging at various levels (client, Nuxt server, Nitro, and your backend services) to trace the exact path and origin of these requests. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3d ago
<@691299263547703317> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?