Skip to content
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

websockify.py not forwarding data just before connection close #63

Closed
ysangkok opened this issue Sep 25, 2012 · 6 comments
Closed

websockify.py not forwarding data just before connection close #63

ysangkok opened this issue Sep 25, 2012 · 6 comments
Labels
bug Something isn't working fixed

Comments

@ysangkok
Copy link

Executing this: ./websockify.py 2300 -- sh -c 'while true; do (echo "test";) | nc -l 2300; done' and opening wstelnet.html, adjusting the address to localhost:2300 and connecting never gives me any output.

This works most of the time, however: ./websockify.py 2300 -- sh -c 'while true; do (echo "test"; sleep 1;) | nc -l 2300; done' (note the sleep)

I am convinced it should work on every connection, cause if I run while true; do sh -c 'echo "test" | nc -l 2300'; done and while true; do nc localhost 2300; done I get the expected output (one line per loop iteration).

I did not try any of the other implementations, but I'd like to know if they have this problem too.

@ysangkok
Copy link
Author

The C version does not have this problem

@WhiteRavenTechnology
Copy link

Sounds a lot like the issue I raised (#36), but with better documentation. :)

Good to know the C version doesn't appear to have the problem, but I haven't had a chance to work on the large message issue there, so a Python fix would be most welcome!

@ysangkok
Copy link
Author

Oh, I guess I was too eager to report there. I'll just keep this open until kanaka sees it. This one can be closed afterwards, of course, I'm pretty sure that this is a duplicate.

@kanaka
Copy link
Member

kanaka commented Oct 29, 2012

Thank you for the test case. That made my life much simpler. And sorry for the slow reply.

Try 5e16b38. It should at least address your test case. I moved the client socket handling earlier in the loop. The problem with the current situation is that if the target immediately closes after sending the data (which seems to happen sporadically even with the sleep), then the data will never be sent to the client because the next time through the loop it will read from the target, detect that it is closed and never reach the client socket handling.

Please also try in the full case where you are seeing the problem. There is still a possible problem where the client socket is busy and so not all the data from the target gets sent, but this is a theoretical possibility and complicates the code so unless people are actually running into I'm hoping this trivial re-ordering will solve what you are actually seeing.

@ysangkok
Copy link
Author

@kanaka : The problem is fixed. The affected test was emscripten/src/runner.py/test_zz_websockets.

@kanaka
Copy link
Member

kanaka commented Oct 30, 2012

Great! Thanks for verifying.

@kanaka kanaka closed this as completed Oct 30, 2012
tenchman pushed a commit to tenchman/websockify that referenced this issue Nov 20, 2013
Should at least mostly address this issue:
novnc#63

The problem is that the target in the test case often immediately
closed the target after sending the data. In this case the last data
received from the target is never sent to the client because the
client is not in the list of sockets being selected against (because
it is only added if their is pending data). By moving the client
conditionals first, we give the client socket a chance to be sent data
before the target is detected as close and we terminate the loop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

3 participants