socket connect failures should trigger POLLOUT
Hi
It looks like socket connect failures aren't triggering a POLLOUT event, which is normal behaviour ("... the socket is nonblocking and the connection cannot be completed immediately. It is possible to select(2) or poll(2) for completion by selecting the socket for writing. After select(2) indicates writability, use getsockopt(2) to read the SO_ERROR option at level SOL_SOCKET to determine whether connect() completed successfully" from the Linux max page, for example).
An example of where this will break is if using ASIO - it only registers for write events on an async connect.
I've hacked around to get this working, but I suspect an actual solution should be better; I don't believe POLLIN should fire at all (and maybe not POLLHUP either) and my hack is quite flakey should more errors than ECONNREFUSED be reported in the future. Maybe needs a bit more state to record connect failures, given the underlying websocket doesn't?
diff --git a/src/library_sockfs.js b/src/library_sockfs.js
index f74346c..2346c2a 100644
--- a/src/library_sockfs.js
+++ b/src/library_sockfs.js
@@ -372,7 +372,9 @@ mergeInto(LibraryManager.library, {
}
if (!dest || // connection-less sockets are always ready to write
- (dest && dest.socket.readyState === dest.socket.OPEN)) {
+ (dest && dest.socket.readyState === dest.socket.OPEN) ||
+ // Failed connects should be reported as POLLOUT.
+ (dest && sock.error === ERRNO_CODES.ECONNREFUSED)) {
mask |= {{{ cDefine('POLLOUT') }}};
}
Regards
Luke Elliott.
This issue has been automatically marked as stale because there has been no activity in the past 2 years. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.
Shame - surely the connect() emulation should behave as standard. Can't it be fixed "properly"? I've been using my hack for years with no problems, though I'm sure a neater solution is preferable :)
[EINPROGRESS] The socket is non-blocking and the connection cannot
be completed immediately. It is possible to select(2)
for completion by selecting the socket **for writing.**
Thanks
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.