You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Nick Williams <ni...@nicholaswilliams.net> on 2013/11/25 03:44:50 UTC

IllegalStateException sending WebSocket message that worked a few months ago

I've written a simple Servlet/WebSocket client that sends a message over the Session each time a GET request comes in. This worked a few months ago:

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        ClusterMessage message = new ClusterMessage(this.nodeId,
                "request:{ip:\"" + request.getRemoteAddr() +
                "\",queryString:\"" + request.getQueryString() + "\"}");

        try(OutputStream output = this.session.getBasicRemote().getSendStream();
            ObjectOutputStream stream = new ObjectOutputStream(output))
        {
            stream.writeObject(message);
        }
        response.getWriter().append("OK");
    }

But on the latest trunk, I get this error on the first request to doGet:

java.lang.IllegalStateException: The remote endpoint was in state [STREAM_WRITING] which is an invalid state for called method
	org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1014)
	org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.binaryPartialStart(WsRemoteEndpointImplBase.java:961)
	org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendPartialBytes(WsRemoteEndpointImplBase.java:140)
	org.apache.tomcat.websocket.WsRemoteEndpointImplBase$WsOutputStream.doWrite(WsRemoteEndpointImplBase.java:838)
	org.apache.tomcat.websocket.WsRemoteEndpointImplBase$WsOutputStream.flush(WsRemoteEndpointImplBase.java:821)
	java.io.ObjectOutputStream$BlockDataOutputStream.flush(ObjectOutputStream.java:1823)
	java.io.ObjectOutputStream.flush(ObjectOutputStream.java:719)
	java.io.ObjectOutputStream.close(ObjectOutputStream.java:740)
	com.wrox.ClusterNodeServlet.doGet(ClusterNodeServlet.java:72)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

On all subsequent requests, I get this error:

java.lang.IllegalStateException: The remote endpoint was in state [STREAM_WRITING] which is an invalid state for called method
	org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1014)
	org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.streamStart(WsRemoteEndpointImplBase.java:951)
	org.apache.tomcat.websocket.WsRemoteEndpointImplBase.getSendStream(WsRemoteEndpointImplBase.java:190)
	org.apache.tomcat.websocket.WsRemoteEndpointBasic.getSendStream(WsRemoteEndpointBasic.java:62)
	com.wrox.ClusterNodeServlet.doGet(ClusterNodeServlet.java:68)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

I'm guessing I need to file a BZ, but I wanted to make sure. I don't see how I could possibly be doing anything wrong in this simple code.

N
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: IllegalStateException sending WebSocket message that worked a few months ago

Posted by Nick Williams <ni...@nicholaswilliams.net>.
On Nov 26, 2013, at 5:32 AM, Mark Thomas wrote:

> On 26/11/2013 04:56, Konstantin Kolinko wrote:
>> 2013/11/26 Nick Williams <ni...@nicholaswilliams.net>:
>>> 
>>> On Nov 25, 2013, at 9:11 PM, Konstantin Kolinko wrote:
>>> 
> 
>>>> There was this change:
>>>> http://svn.apache.org/viewvc?view=revision&revision=1544213
>>>> 
>>>>     <fix>
>>>>       <bug>55799</bug>: Correctly enforce the restriction in JSR356 that no
>>>>       more than one data message may be sent to a remote WebSocket endpoint at
>>>>       a time. (markt)
>>>>     </fix>
>>> 
>>> Problem is, I'm only sending one data message. That's it. The very first and only data message I send triggers the first error. The second error is before I even get to sending a data message; it's when I retrieve a stream. Something's definitely broken. Even IF I were sending multiple messages (again, I'm not); they should be queued, not result in an error that leaves the Session in an inconsistent state indefinitely.
>> 
>> 
>> I reopened the bug,
>> https://issues.apache.org/bugzilla/show_bug.cgi?id=55799#c15
> 
> Fixed.
> 
> Mark

Your changes only partially fixed it. I'm still having problems with latest trunk. I have reopened the bug and attached a sample project to it that replicates the regression.

Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: IllegalStateException sending WebSocket message that worked a few months ago

Posted by Mark Thomas <ma...@apache.org>.
On 26/11/2013 04:56, Konstantin Kolinko wrote:
> 2013/11/26 Nick Williams <ni...@nicholaswilliams.net>:
>>
>> On Nov 25, 2013, at 9:11 PM, Konstantin Kolinko wrote:
>>

>>> There was this change:
>>> http://svn.apache.org/viewvc?view=revision&revision=1544213
>>>
>>>      <fix>
>>>        <bug>55799</bug>: Correctly enforce the restriction in JSR356 that no
>>>        more than one data message may be sent to a remote WebSocket endpoint at
>>>        a time. (markt)
>>>      </fix>
>>
>> Problem is, I'm only sending one data message. That's it. The very first and only data message I send triggers the first error. The second error is before I even get to sending a data message; it's when I retrieve a stream. Something's definitely broken. Even IF I were sending multiple messages (again, I'm not); they should be queued, not result in an error that leaves the Session in an inconsistent state indefinitely.
> 
> 
> I reopened the bug,
> https://issues.apache.org/bugzilla/show_bug.cgi?id=55799#c15

Fixed.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: IllegalStateException sending WebSocket message that worked a few months ago

Posted by Konstantin Kolinko <kn...@gmail.com>.
2013/11/26 Nick Williams <ni...@nicholaswilliams.net>:
>
> On Nov 25, 2013, at 9:11 PM, Konstantin Kolinko wrote:
>
>> 2013/11/25 Nick Williams <ni...@nicholaswilliams.net>:
>>> I've written a simple Servlet/WebSocket client that sends a message over the Session each time a GET request comes in. This worked a few months ago:
>>>
>>>    @Override
>>>    protected void doGet(HttpServletRequest request, HttpServletResponse response)
>>>            throws ServletException, IOException
>>>    {
>>>        ClusterMessage message = new ClusterMessage(this.nodeId,
>>>                "request:{ip:\"" + request.getRemoteAddr() +
>>>                "\",queryString:\"" + request.getQueryString() + "\"}");
>>>
>>>        try(OutputStream output = this.session.getBasicRemote().getSendStream();
>>>            ObjectOutputStream stream = new ObjectOutputStream(output))
>>>        {
>>>            stream.writeObject(message);
>>>        }
>>>        response.getWriter().append("OK");
>>>    }
>>>
>>> But on the latest trunk, I get this error on the first request to doGet:
>>>
>>> java.lang.IllegalStateException: The remote endpoint was in state [STREAM_WRITING] which is an invalid state for called method
>>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1014)
>>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.binaryPartialStart(WsRemoteEndpointImplBase.java:961)
>>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendPartialBytes(WsRemoteEndpointImplBase.java:140)
>>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase$WsOutputStream.doWrite(WsRemoteEndpointImplBase.java:838)
>>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase$WsOutputStream.flush(WsRemoteEndpointImplBase.java:821)
>>>        java.io.ObjectOutputStream$BlockDataOutputStream.flush(ObjectOutputStream.java:1823)
>>>        java.io.ObjectOutputStream.flush(ObjectOutputStream.java:719)
>>>        java.io.ObjectOutputStream.close(ObjectOutputStream.java:740)
>>>        com.wrox.ClusterNodeServlet.doGet(ClusterNodeServlet.java:72)
>>>        javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
>>>        javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
>>>        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
>>>
>>> On all subsequent requests, I get this error:
>>>
>>> java.lang.IllegalStateException: The remote endpoint was in state [STREAM_WRITING] which is an invalid state for called method
>>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1014)
>>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.streamStart(WsRemoteEndpointImplBase.java:951)
>>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase.getSendStream(WsRemoteEndpointImplBase.java:190)
>>>        org.apache.tomcat.websocket.WsRemoteEndpointBasic.getSendStream(WsRemoteEndpointBasic.java:62)
>>>        com.wrox.ClusterNodeServlet.doGet(ClusterNodeServlet.java:68)
>>>        javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
>>>        javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
>>>        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
>>>
>>> I'm guessing I need to file a BZ, but I wanted to make sure. I don't see how I could possibly be doing anything wrong in this simple code.
>>>
>>
>>
>> There was this change:
>> http://svn.apache.org/viewvc?view=revision&revision=1544213
>>
>>      <fix>
>>        <bug>55799</bug>: Correctly enforce the restriction in JSR356 that no
>>        more than one data message may be sent to a remote WebSocket endpoint at
>>        a time. (markt)
>>      </fix>
>
> Problem is, I'm only sending one data message. That's it. The very first and only data message I send triggers the first error. The second error is before I even get to sending a data message; it's when I retrieve a stream. Something's definitely broken. Even IF I were sending multiple messages (again, I'm not); they should be queued, not result in an error that leaves the Session in an inconsistent state indefinitely.


I reopened the bug,
https://issues.apache.org/bugzilla/show_bug.cgi?id=55799#c15

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: IllegalStateException sending WebSocket message that worked a few months ago

Posted by Nick Williams <ni...@nicholaswilliams.net>.
On Nov 25, 2013, at 9:11 PM, Konstantin Kolinko wrote:

> 2013/11/25 Nick Williams <ni...@nicholaswilliams.net>:
>> I've written a simple Servlet/WebSocket client that sends a message over the Session each time a GET request comes in. This worked a few months ago:
>> 
>>    @Override
>>    protected void doGet(HttpServletRequest request, HttpServletResponse response)
>>            throws ServletException, IOException
>>    {
>>        ClusterMessage message = new ClusterMessage(this.nodeId,
>>                "request:{ip:\"" + request.getRemoteAddr() +
>>                "\",queryString:\"" + request.getQueryString() + "\"}");
>> 
>>        try(OutputStream output = this.session.getBasicRemote().getSendStream();
>>            ObjectOutputStream stream = new ObjectOutputStream(output))
>>        {
>>            stream.writeObject(message);
>>        }
>>        response.getWriter().append("OK");
>>    }
>> 
>> But on the latest trunk, I get this error on the first request to doGet:
>> 
>> java.lang.IllegalStateException: The remote endpoint was in state [STREAM_WRITING] which is an invalid state for called method
>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1014)
>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.binaryPartialStart(WsRemoteEndpointImplBase.java:961)
>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendPartialBytes(WsRemoteEndpointImplBase.java:140)
>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase$WsOutputStream.doWrite(WsRemoteEndpointImplBase.java:838)
>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase$WsOutputStream.flush(WsRemoteEndpointImplBase.java:821)
>>        java.io.ObjectOutputStream$BlockDataOutputStream.flush(ObjectOutputStream.java:1823)
>>        java.io.ObjectOutputStream.flush(ObjectOutputStream.java:719)
>>        java.io.ObjectOutputStream.close(ObjectOutputStream.java:740)
>>        com.wrox.ClusterNodeServlet.doGet(ClusterNodeServlet.java:72)
>>        javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
>>        javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
>>        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
>> 
>> On all subsequent requests, I get this error:
>> 
>> java.lang.IllegalStateException: The remote endpoint was in state [STREAM_WRITING] which is an invalid state for called method
>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1014)
>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.streamStart(WsRemoteEndpointImplBase.java:951)
>>        org.apache.tomcat.websocket.WsRemoteEndpointImplBase.getSendStream(WsRemoteEndpointImplBase.java:190)
>>        org.apache.tomcat.websocket.WsRemoteEndpointBasic.getSendStream(WsRemoteEndpointBasic.java:62)
>>        com.wrox.ClusterNodeServlet.doGet(ClusterNodeServlet.java:68)
>>        javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
>>        javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
>>        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
>> 
>> I'm guessing I need to file a BZ, but I wanted to make sure. I don't see how I could possibly be doing anything wrong in this simple code.
>> 
> 
> 
> There was this change:
> http://svn.apache.org/viewvc?view=revision&revision=1544213
> 
>      <fix>
>        <bug>55799</bug>: Correctly enforce the restriction in JSR356 that no
>        more than one data message may be sent to a remote WebSocket endpoint at
>        a time. (markt)
>      </fix>

Problem is, I'm only sending one data message. That's it. The very first and only data message I send triggers the first error. The second error is before I even get to sending a data message; it's when I retrieve a stream. Something's definitely broken. Even IF I were sending multiple messages (again, I'm not); they should be queued, not result in an error that leaves the Session in an inconsistent state indefinitely.

N
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: IllegalStateException sending WebSocket message that worked a few months ago

Posted by Konstantin Kolinko <kn...@gmail.com>.
2013/11/25 Nick Williams <ni...@nicholaswilliams.net>:
> I've written a simple Servlet/WebSocket client that sends a message over the Session each time a GET request comes in. This worked a few months ago:
>
>     @Override
>     protected void doGet(HttpServletRequest request, HttpServletResponse response)
>             throws ServletException, IOException
>     {
>         ClusterMessage message = new ClusterMessage(this.nodeId,
>                 "request:{ip:\"" + request.getRemoteAddr() +
>                 "\",queryString:\"" + request.getQueryString() + "\"}");
>
>         try(OutputStream output = this.session.getBasicRemote().getSendStream();
>             ObjectOutputStream stream = new ObjectOutputStream(output))
>         {
>             stream.writeObject(message);
>         }
>         response.getWriter().append("OK");
>     }
>
> But on the latest trunk, I get this error on the first request to doGet:
>
> java.lang.IllegalStateException: The remote endpoint was in state [STREAM_WRITING] which is an invalid state for called method
>         org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1014)
>         org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.binaryPartialStart(WsRemoteEndpointImplBase.java:961)
>         org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendPartialBytes(WsRemoteEndpointImplBase.java:140)
>         org.apache.tomcat.websocket.WsRemoteEndpointImplBase$WsOutputStream.doWrite(WsRemoteEndpointImplBase.java:838)
>         org.apache.tomcat.websocket.WsRemoteEndpointImplBase$WsOutputStream.flush(WsRemoteEndpointImplBase.java:821)
>         java.io.ObjectOutputStream$BlockDataOutputStream.flush(ObjectOutputStream.java:1823)
>         java.io.ObjectOutputStream.flush(ObjectOutputStream.java:719)
>         java.io.ObjectOutputStream.close(ObjectOutputStream.java:740)
>         com.wrox.ClusterNodeServlet.doGet(ClusterNodeServlet.java:72)
>         javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
>         javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
>         org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
>
> On all subsequent requests, I get this error:
>
> java.lang.IllegalStateException: The remote endpoint was in state [STREAM_WRITING] which is an invalid state for called method
>         org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1014)
>         org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.streamStart(WsRemoteEndpointImplBase.java:951)
>         org.apache.tomcat.websocket.WsRemoteEndpointImplBase.getSendStream(WsRemoteEndpointImplBase.java:190)
>         org.apache.tomcat.websocket.WsRemoteEndpointBasic.getSendStream(WsRemoteEndpointBasic.java:62)
>         com.wrox.ClusterNodeServlet.doGet(ClusterNodeServlet.java:68)
>         javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
>         javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
>         org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
>
> I'm guessing I need to file a BZ, but I wanted to make sure. I don't see how I could possibly be doing anything wrong in this simple code.
>


There was this change:
http://svn.apache.org/viewvc?view=revision&revision=1544213

      <fix>
        <bug>55799</bug>: Correctly enforce the restriction in JSR356 that no
        more than one data message may be sent to a remote WebSocket endpoint at
        a time. (markt)
      </fix>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org