-
Notifications
You must be signed in to change notification settings - Fork 4
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
Debug the ConnectionReverse
warning: [ERR_STREAM_WRITE_AFTER_END]: write after end
#300
Comments
Is this in master? Any new changes affecting networking domain atm? |
@joshuakarp have a read of the connection compose logic see where writes could occur. |
Yeah, in master. This has been around for several months (as early as the test was added back in May here https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/178#note_583511389) - just created this issue to keep track of it. |
This is the sort of bug we can use our new VSCode debugger powers for. Maybe have a try at it soon @joshuakarp. |
Good idea - will take a bit of a look into it now. |
It's actually rather difficult to use these options to debug something that uses then "Step Into": You can mitigate this a bit by adding a breakpoint in the called |
For this particular issue though, the warning message arises after closing the public async stop(): Promise<void> {
this.logger.info('Stopping Forward Proxy Server');
const serverClose = promisify(this.server.close).bind(this.server);
await serverClose();
// Ensure no new connections are created while this is iterating
await Promise.all(
Array.from(this.connections.ingress, ([, conn]) => conn.stop()),
);
// Delay socket close by about 1 second
// this gives some time for the end/FIN packets to be sent
await sleep(1000);
// Even when all connections are destroyed
// the utp socket sometimes hangs in closing
// here we asynchronously close and unreference it
// in order to speed up the closing
this.utpSocket.close();
this.utpSocket.unref();
this.logger.info('Stopped Forward Proxy Server');
} It's also a little tricky to debug this with the debugger because the operations aren't sequential (because of the networking going on under the hood). So often the error will be a timeout error instead if we pause on the breakpoint for too long. |
Well it looks like you found it. This error can arise due to: // Delay socket close by about 1 second
// this gives some time for the end/FIN packets to be sent
await sleep(1000);
// Even when all connections are destroyed
// the utp socket sometimes hangs in closing
// here we asynchronously close and unreference it
// in order to speed up the closing
this.utpSocket.close(); Which means the socket got closed during the sleep. And then when you call At least this is what seems to be the case. One way to get around this is maybe checking if the socket is already closed, and if so don't bother calling close again. I didn't expect the socket to be closed at that point though. Maybe something else is causing the socket to be closed. The sleep is only there to wait for all connections to stop, not necessarily for the "socket" to be closed. If you check if the socket is closed prior, does the warning still occur? |
It could also be that we have closed the UTP socket but the connection failed to stop in time. That's why there's a |
The next question is why is the connection taking so long to close? I had investigated this prior but didn't find the reason, hence for the comment I wrote there. This may just be an intermittent error. It may not affect normal operations... |
The real reason may be in the C++ codebase that is not worth going into until we have swapped out UTP with something more robust like QUIC or webrtc. #234 |
This is the jest test that it occured on for me:
When running this in a normal test.ts file the code hung instead of giving the warning. That may have been because I set it up incorrectly though |
It's actually occurring before we even reach the public async stop(): Promise<void> {
this.logger.info('Stopping Forward Proxy Server');
const serverClose = promisify(this.server.close).bind(this.server);
await serverClose();
// Ensure no new connections are created while this is iterating
await Promise.all(
Array.from(this.connections.ingress, ([, conn]) => conn.stop()),
);
// Delay socket close by about 1 second
// this gives some time for the end/FIN packets to be sent
await sleep(1000);
// Even when all connections are destroyed
// the utp socket sometimes hangs in closing
// here we asynchronously close and unreference it
// in order to speed up the closing
this.logger.info('Closing the socket'); // breakpoint here
this.utpSocket.close();
this.utpSocket.unref();
this.logger.info('Stopped Forward Proxy Server');
} We get the following output:
No change, still the same.
I haven't come across an instance of this warning that's caused an actual issue with the implementation. |
Interestingly, if I change the order of shutdown in await client.destroy();
await fwdProxy.stop();
await revProxy.stop();
await closeTestServer(server);
}); to await client.destroy();
await revProxy.stop();
await fwdProxy.stop();
await closeTestServer(server);
}); we no longer get the warning. |
This may actually be a problem coming from So the reason the error is being emitted is because when the In the When the However in our case when we set Strangely it doesn't occur when we do the same for Due to mafintosh/utp-native#41 I believe that there are some underlying issues in For now, we can do is to simply remove the
The We can do the same to Alternatively if we can find a boolean condition for whether something can be ended or not, that would also work and possibly be more robust if in the future we do enable |
The above problem I believe will be solved by applying this solution #292 (comment) to the reverse proxy as well. I'm also changing
|
Describe the bug
We've started to notice a particular warning popping up in various parts of the codebase that utilise the networking domain. Namely, the following warning:
My initial thought is that this is potentially just a warning message that is being erroneously propagated up to the console output when a connection is torn down. But further investigation is required.
To Reproduce
We've noticed this occur in a few different areas:
When running
tests/network/index.test.ts
:dfsd
Expected behavior
No warning message to appear at all (either by resolving some underlying issue that's causing a stream to be written to, or by stopping the warning message from propagating up).
Additional context
network/index.test.ts
: https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/178#note_583511389ERROR
outputs were also being propagated up to the console output (as per the test output) but this is no longer the case in the most recent iteration ofindex.test.ts
Notify maintainers
@CMCDragonkai
The text was updated successfully, but these errors were encountered: