-
Notifications
You must be signed in to change notification settings - Fork 1
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
Replace keydown with hidden input #4
Changes from 5 commits
7460f61
78cc727
0eefb4c
258ce6a
9fffce8
ce6782c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -40,7 +40,12 @@ export class BroadcastMethods<T extends Record<string, Function>> { | |||||||||||||
const result = await methods[fn](...args) | ||||||||||||||
chan.postMessage({ result, requestId }) | ||||||||||||||
} catch (error) { | ||||||||||||||
chan.postMessage({ error, requestId }) | ||||||||||||||
console.error('Can\'t post results, trying to send the error', error) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the specific error? It would be bad if this always silently failed? Doesn't this mean this broadcast channel should now be abandoned and a new one needs to be created? Why exactly is this failing? If you could do something like the below, filling in the
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh got it, I'll check and see what is the actual error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok the exception is because the websocket i'm trying to send a message to has already closed. Fumbling with this it seems that there are also other uncaught exceptions all regarding this kind of issues (if someone leaves and the game is still open it will still fail). I'm still not entirely sure on the reproduction steps but given it's not the only point where the disconnection can cause unhandled exceptions i think it might be better to do a complete check in another issue (i can do it myself but i might need your help to better understand the backend code without the need to read the whole codebase). Let me know how do you want to handle this, if you prefer i might add an error similar to what you've proposed in the meantime. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it throw this error if you connect two tabs to the game and one tab closes ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's kinda strange because that's exactly the other error i was talking about: if you enter with two person and quit with one it will throw an unhandled error but only at the end of the game not during the "typing events". |
||||||||||||||
try{ | ||||||||||||||
chan.postMessage({ error, requestId }) | ||||||||||||||
}catch(e){ | ||||||||||||||
console.error('BroadcastChannel is dead failed to send error', e) | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mfbx9da4 i've finally come around to take a look at the server code: what was happening was that it tried to send a message before broadcasting, but given that the socket was not open it would've failed to send and call the destroy method that would've also close the channel.
I've added a check for the readystate of the socket before trying to send and this should fix the error that would cause the server to crash.
I was able to find a reproduction if you want to try on your own:
This is what caused the server to crash before (it will not crash with this fix)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the issue that the user left the game and so the web socket connection is now closed and we don't gracefully handle connections being closed?
If the user's connection has dropped, it's fine to just not send messages. So I think your change makes a lot of sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah basically the websocket it's closed, in the broadcast method it calls the send method which tries to send a message to the websocket, failing to do so it closes the channel. After the send method the broadcast method tries to post a message but the channel was just closed by the websocket and so it fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mfbx9da4 any news? Do i need to do something else or can we merge this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah just one final thing, could you run prettier on your changes? Also there should be a
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right...did it and pushed a new commit 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like you ran prettier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh i don't know what happened...redid it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mfbx9da4 don't know if you missed this