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

Closing/interrupting UnixServerSocket #52

Open
krisskross opened this issue Dec 30, 2017 · 1 comment
Open

Closing/interrupting UnixServerSocket #52

krisskross opened this issue Dec 30, 2017 · 1 comment

Comments

@krisskross
Copy link

krisskross commented Dec 30, 2017

I haven't found a way of shutting down a UnixServerSocket that's waiting for incoming sockets in accept(). It also doesn't respond thread interrupts?

The code looks a little like this - and the accept still hangs after the interupt.

Thread thread = new Thread(() -> {
    UnixSocketAddress socketAddress = new UnixSocketAddress("/tmp/file.sock");
    UnixServerSocket serverSocket = new UnixServerSocket();
    serverSocket.bind(socketAddress);
    while (true) {
      UnixSocket sock = null;
      try {
        sock = serverSocket.accept();
        // ... do stuff
      } catch (Exception e) {
        if (sock != null) {
          sock.close();
        }
      }
      System.out.println("I surrender");
    }
});
thread.start();
Thread.sleep(2000);
thread.interrupt();
Thread.sleep(10000);
@gregw
Copy link
Contributor

gregw commented Nov 22, 2018

I think this is a duplicate of #21. I proposed a fix in #25, but that is now stale and needs to be freshened up to be ready for a merge.

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

2 participants