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

Calling close on a UnixSocket with a pending read waits for the read to time out on Linux #60

Closed
charleskorn opened this issue Sep 23, 2018 · 4 comments

Comments

@charleskorn
Copy link
Contributor

If you create a UnixSocket, set a read timeout and then:

  • call read() on one thread
  • wait a bit and then call close() on another thread

...the behaviour is different on OS X and Linux.

On OS X, the read is cancelled as soon as close() is called and so close() returns immediately. On Linux, the read blocks until the read timeout is reached, and then close() returns.

This makes interrupting read operations impossible, and is the root cause of square/okhttp#4233.

I have created a test case that fails on Linux (but passes on OS X) in charleskorn@b0981ae.

@charleskorn
Copy link
Contributor Author

I don't know much about sockets programming, but reading https://www.systutorials.com/docs/linux/man/2-close/ suggests that calling shutdown on the socket before calling close is the correct behaviour. Calling shutdownInput() and shutdownOutput() in AbstractNativeSocketChannel.implCloseSelectableChannel() fixes this.

charleskorn added a commit to batect/batect that referenced this issue Sep 23, 2018
@headius
Copy link
Member

headius commented Feb 11, 2019

@charleskorn Can you propose a PR to fix this?

@charleskorn
Copy link
Contributor Author

Done - #68.

@selckin
Copy link

selckin commented Dec 2, 2019

This also fixes an issue with docker-maven-plugin for me see fabric8io/docker-maven-plugin#552

@headius headius closed this as completed in 61fa89d Jan 9, 2020
headius added a commit that referenced this issue Jan 9, 2020
Fix #60 (calling close on a UnixSocket with a pending read waits for the read to time out on Linux)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants