Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0006326 [Resin] minor always 02-14-20 06:03 03-11-20 15:07
Reporter James Byatt View Status public  
Assigned To ferg
Priority normal Resolution fixed  
Status closed   Product Version 4.0.64
Summary 0006326: com.caucho.remote.websocket.WebSocketWriter transforms all IOExceptions into IllegalStateExceptions
Description Hello,

We've written an application that makes use of resin's websockets, and we have some sending code that looks something like this:

WebSocketContext context = ... // we're called back with this object when the websocket starts
try (final PrintWriter writer = context.startTextMessage())
   writer.print("Hello world!")

Now - this usually works - unless the client at the other end has disconnected in the meantime. If that has happened, the root socket connection throws a SocketException, which eventually bubbles up into WebSocketWriter...which rethrows it as an IllegalStateException (!). Looking at the source, WebSocketWriter appears to do this everywhere it can. Here's its flush method, for example:

  public void flush()
    try {

    } catch (IOException e) {
      throw new IllegalStateException(e);

This makes it very difficult for client code to discern problems caused by changes in connectivity from, well, anything else. I can sort of see why this choice would be made - PrintWriter hides IOExceptions behind a `trouble` boolean, and people might not know to call `checkError`. I'd argue that's their problem, not resin's, and behaving in what to me feels non-idiomatic makes things worse.

I'm not sure what the solution is here. Here, though, are some suggestions you should feel free to ignore :-)

- Maybe provide Writer instead of PrintWriter from startTextMessage?
  Breaks backwards compatibility :-(
  Could provide a different call, deprecate the existing startTextMessage, advise users, etc?
- Throw a well documented exception type other than IllegalStateException?
  Still a bit icky
- Something else?

Happy to discuss this further, be corrected, etc - let me know!


P.S We're using 4.0.62, but a quick check of 4.0.64's source tells me that nothing has changed.

Additional Information Here's a stack trace:

java.lang.IllegalStateException: com.caucho.vfs.ClientDisconnectException: SocketStream[null] Socket closed
    at com.caucho.remote.websocket.WebSocketWriter.close(
    at com.caucho.remote.websocket.WebSocketPrintWriter.close(
        ...killed a few frames of our calling code here...
Caused by: com.caucho.vfs.ClientDisconnectException: SocketStream[null] Socket closed
    at com.caucho.vfs.ClientDisconnectException.create(
    at com.caucho.vfs.SocketStream.write(
    at com.caucho.vfs.WriteStream.flush(
    at com.caucho.remote.websocket.WebSocketWriter.close(
    ... 8 more
Caused by: Socket closed
    at com.caucho.vfs.SocketStream.write(
    ... 10 more
Attached Files

- Relationships

There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
02-14-20 06:03 James Byatt New Issue
03-11-20 15:07 ferg Assigned To  => ferg
03-11-20 15:07 ferg Status new => closed
03-11-20 15:07 ferg Resolution open => fixed
03-11-20 15:07 ferg Fixed in Version  => 4.0.65

Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
27 total queries executed.
25 unique queries executed.
Powered by Mantis Bugtracker