-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP request is sent twice in Node app #1416
Comments
Hi @b1nks,
What do the two request logs in the target server look like? |
I tried your code to send to the local server running nginx.
But I only see one access log in nginx. Could you try it with a local server like nginx? |
I ran this config without Docker and everything is fine, no double request sending occurs |
Hello. Is there any news on this issue? |
Hi! Apologies, we've been busy releasing version 1.33 and some associated tasks. I am going to look at this this week and should have an update for you soon. |
Additional details for others to replicate this that was needed to look into this:
const options = {
hostname: "webhook.site",
port: 80,
path: "/21d0ae48-4210-4c87-b4a5-a81649357386",
method: "GET",
};
const server = http.createServer({}, (req, res) => {
res.writeHead(200, {"Content-Type": "text/plain"});
res.end("Hello, Node.js on Unit!")
});
@b1nks do you have a more functional code you can paste here where you can reproduce the issue that when you send 1 request to Unit, it results in 2 requests to webhook.site? |
I initially got this problem when I added a handler for a Mongo data change event to my app. My app is a fairly simple configuration with express.js and of course I use a more complete initialization from the documentation. Dockerfile
unit-config.json
index.js
handleChangeActive can have any implementation, including sending a request to webhook.site. This is always a double send. |
Thank you for this. To make sure I understand your flow correctly:
As I don't have the actual application (I'm missing the models and handlers.js as well as the package.json) and I don't know enough about nodejs and mongoose here to fill in the blanks, and even then it would be different, could you double check something for me? I'm curious, how many times is The question I'm trying to find out is whether the double call happens because the model has a double update, but each update correctly sends a single call to If you run this application on your host machine outside of Unit, does the issue get resolved? |
Thanks for this clarifying question, it helped me to discover some facts that I hadn't noticed before. However, I don't think that mongoose itself can be involved in this behavior, because I tried sending the request in other ways without the participation of any third-party libraries, including using a simple implementation of event emitter. Unfortunately, I can't run my application on the host machine, but I will try to make a similar configuration and make sure that it works correctly. |
Can you link me to the event emitter example, or paste in a fully working code that I can copy paste as-is? It would help a lot if you had a minimum reproduction example we can look at so we can remove as much of the possibility of a user application doing unexpected things and hone in on Unit sending a double request. |
Sorry for the long absence. Dockerfile
index.js
unit-config.json
|
Hey @b1nks, Thank you for this. I copy-pasted this code to check what's happening, created my own webhook.site. Here's what's happening:
My assumption is that Unit's start-stop-start in Docker is tripping you up and that's what you're seeing as a weird double request. That is by design. We're working on making that more seamless as we've bumped into issues with the start-stop-start from others as well. Let me know if you're experiencing something different. If this is what's the original issue, then Unit is behaving as designed. I do admit that the start-stop-start isn't spelled out explicitly in the documentation: https://unit.nginx.org/installation/#initial-configuration |
oh.. |
Hello! That's all right, glad I could clarify things 🙂 . I'm going to close this issue as answered. Have an excellent week ahead! |
I'm using unit:node Docker image and I encountered double sending of http requests.
Looks like a bug, but I'm not qualified enough to dive deeper into the problem.
The situation can be repeated on the simplest configuration:
The text was updated successfully, but these errors were encountered: