You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Farzad Panahi <fa...@gmail.com> on 2015/10/28 03:15:02 UTC

Tomcat throws IllegalStateException “The remote endpoint was in state [BINARY_FULL_WRITING] …” when calling RemoteEndpoint.Async.sendBinary concurrently on the same session

Hi,

I am using tomcat 8.0.23 to terminate my websocket connections. I have
the following code to take care of the incoming messages:

@OnMessage
public void onMsg(Session session, byte[] request) {
        executorService.execute(() ->
                session.getAsyncRemote().sendBinary(
                        ByteBuffer.wrap(getResponse(session,
request)), result -> {
                            if (!result.isOK()) {
                                LOGGER.catching(result.getException());
                            }
                        }
                ));
}

But I get the following exception:

Exception in thread "pool-6-thread-10160"
java.lang.IllegalStateException: The remote endpoint was in state
[BINARY_FULL_WRITING] which is an invalid state for called method
    at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1148)
    at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.binaryStart(WsRemoteEndpointImplBase.java:1101)
    at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendBytesByCompletion(WsRemoteEndpointImplBase.java:152)
    at org.apache.tomcat.websocket.WsRemoteEndpointAsync.sendBinary(WsRemoteEndpointAsync.java:65)

>From what I understand from java doc, RemoteEndpoint.Async.sendBinary
should not throw IllegalStateException:

> sendBinary void sendBinary(ByteBuffer data, SendHandler handler)
> Throws: IllegalArgumentException - if either the data or the handler are null.

It is also good to note that RemoEndpoint.Basic (not
RemoteEndpoint.Async) has the following paragraph in java doc:

> If the websocket connection underlying this RemoteEndpoint is busy sending a  message when a call is made to send another one, for example if two threads  attempt to call a send method concurrently, or if a developer attempts to send a new message while in the middle of sending an existing one, the send method called while the connection is already busy may throw an IllegalStateException.


Is this expected behaviour from tomcat or a possible implementation bug?


Cheers

Farzad

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


Re: Tomcat throws IllegalStateException “The remote endpoint was in state [BINARY_FULL_WRITING] …” when calling RemoteEndpoint.Async.sendBinary concurrently on the same session

Posted by Mark Thomas <ma...@apache.org>.
On 27/10/2015 19:33, Farzad Panahi wrote:
> Thanks Mark for your quick response.
> 
> But how do I know the previous message is finished? RemoteEndpoint
> does not expose the state.

Yes it does. Via the Future or the SendHandler depending on how you sent
the async message.

For the Basic handler, the message is considered sent once the method
call to send the message returns.

Mark


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


Re: Tomcat throws IllegalStateException “The remote endpoint was in state [BINARY_FULL_WRITING] …” when calling RemoteEndpoint.Async.sendBinary concurrently on the same session

Posted by Farzad Panahi <fa...@gmail.com>.
Thanks Mark for your quick response.

But how do I know the previous message is finished? RemoteEndpoint
does not expose the state.

On Tue, Oct 27, 2015 at 7:30 PM, Mark Thomas <ma...@apache.org> wrote:
> On 27/10/2015 19:15, Farzad Panahi wrote:
>> Hi,
>>
>> I am using tomcat 8.0.23 to terminate my websocket connections. I have
>> the following code to take care of the incoming messages:
>>
>> @OnMessage
>> public void onMsg(Session session, byte[] request) {
>>         executorService.execute(() ->
>>                 session.getAsyncRemote().sendBinary(
>>                         ByteBuffer.wrap(getResponse(session,
>> request)), result -> {
>>                             if (!result.isOK()) {
>>                                 LOGGER.catching(result.getException());
>>                             }
>>                         }
>>                 ));
>> }
>>
>> But I get the following exception:
>>
>> Exception in thread "pool-6-thread-10160"
>> java.lang.IllegalStateException: The remote endpoint was in state
>> [BINARY_FULL_WRITING] which is an invalid state for called method
>>     at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1148)
>>     at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.binaryStart(WsRemoteEndpointImplBase.java:1101)
>>     at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendBytesByCompletion(WsRemoteEndpointImplBase.java:152)
>>     at org.apache.tomcat.websocket.WsRemoteEndpointAsync.sendBinary(WsRemoteEndpointAsync.java:65)
>>
>> From what I understand from java doc, RemoteEndpoint.Async.sendBinary
>> should not throw IllegalStateException:
>>
>>> sendBinary void sendBinary(ByteBuffer data, SendHandler handler)
>>> Throws: IllegalArgumentException - if either the data or the handler are null.
>>
>> It is also good to note that RemoEndpoint.Basic (not
>> RemoteEndpoint.Async) has the following paragraph in java doc:
>>
>>> If the websocket connection underlying this RemoteEndpoint is busy sending a  message when a call is made to send another one, for example if two threads  attempt to call a send method concurrently, or if a developer attempts to send a new message while in the middle of sending an existing one, the send method called while the connection is already busy may throw an IllegalStateException.
>>
>>
>> Is this expected behaviour from tomcat or a possible implementation bug?
>
> The behaviour is expected. You can't start a new message until the
> previous one has finished.
>
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

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


Re: Tomcat throws IllegalStateException “The remote endpoint was in state [BINARY_FULL_WRITING] …” when calling RemoteEndpoint.Async.sendBinary concurrently on the same session

Posted by Mark Thomas <ma...@apache.org>.
On 27/10/2015 19:15, Farzad Panahi wrote:
> Hi,
> 
> I am using tomcat 8.0.23 to terminate my websocket connections. I have
> the following code to take care of the incoming messages:
> 
> @OnMessage
> public void onMsg(Session session, byte[] request) {
>         executorService.execute(() ->
>                 session.getAsyncRemote().sendBinary(
>                         ByteBuffer.wrap(getResponse(session,
> request)), result -> {
>                             if (!result.isOK()) {
>                                 LOGGER.catching(result.getException());
>                             }
>                         }
>                 ));
> }
> 
> But I get the following exception:
> 
> Exception in thread "pool-6-thread-10160"
> java.lang.IllegalStateException: The remote endpoint was in state
> [BINARY_FULL_WRITING] which is an invalid state for called method
>     at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1148)
>     at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.binaryStart(WsRemoteEndpointImplBase.java:1101)
>     at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendBytesByCompletion(WsRemoteEndpointImplBase.java:152)
>     at org.apache.tomcat.websocket.WsRemoteEndpointAsync.sendBinary(WsRemoteEndpointAsync.java:65)
> 
> From what I understand from java doc, RemoteEndpoint.Async.sendBinary
> should not throw IllegalStateException:
> 
>> sendBinary void sendBinary(ByteBuffer data, SendHandler handler)
>> Throws: IllegalArgumentException - if either the data or the handler are null.
> 
> It is also good to note that RemoEndpoint.Basic (not
> RemoteEndpoint.Async) has the following paragraph in java doc:
> 
>> If the websocket connection underlying this RemoteEndpoint is busy sending a  message when a call is made to send another one, for example if two threads  attempt to call a send method concurrently, or if a developer attempts to send a new message while in the middle of sending an existing one, the send method called while the connection is already busy may throw an IllegalStateException.
> 
> 
> Is this expected behaviour from tomcat or a possible implementation bug?

The behaviour is expected. You can't start a new message until the
previous one has finished.

Mark


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