-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Fix netcat hang when it send raw data to raw socket #338
Conversation
netcat and similar tools hang when they send data to PAPPL's raw socket. It is because these tools wait for input from the destination, and we never end because update `activity` every time `poll()` returns non-negative value, and the tools never send POLLHUP. The proposed fix is to update `activity` only when we read from the socket, and break out of the loop after 10s of inactivity. Fixes michaelrsweet#331
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.
netcat doesn't behave like the socket backend or any other JetDirect client - when you are done sending data your data you either close the socket or shutdown the outgoing part of the socket, which will signal PAPPL that things are done. netcat is more like a dumb implementation of telnet...
Also, POLLHUP is output only; from the man page:
POLLHUP The device or socket has been disconnected. This flag is
output only, and ignored if present in the input events
bitmask. Note that POLLHUP and POLLOUT are mutually
exclusive and should never be present in the revents
bitmask at the same time.
As for only updating activity when there is data to be read, it makes sense so that part of your change at least can be adopted.
Finally, it looks like you have a bunch of gratuitous whitespace changes?
I checked netcat and nc (nmap implementation of netcat iiuc) and both were polling the descriptor for events when the binary looked frozen, and the printer application was in pappl iterating in infinite loop with poll().
I've added it to requested events only for formal reasons - IIUC 'man poll', POLLHUP is always returned in revents if appeared, I meant it like stressing out we check POLLHUP event later (even if it is ignored in events).
Bunch of blocks did not follow the code style (unless you've changed the guidelines to differ from CUPS) in the function - 8 spaces weren't substituted by a tab - so I've updated the code to follow the rule. I made it as a separate commit in the PR, so anyone backporting the real fix won't get unnecessary whitespace changes. |
netcat and similar tools hang when they send data to PAPPL's raw socket. It is because these tools wait for input from the destination, and we never end because update
activity
every timepoll()
returns non-negative value, and the tools never send POLLHUP.The proposed fix is to update
activity
only when we read from the socket, and break out of the loop after 10s of inactivity.Fixes #331