Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Async IO failed with IllegalStateException in HttpOutput

Hello Simone,

1) I'll try the master branch and let you know.
2) My current test case is not easily convertible to something without using other code in my project; I can try to create a small test case that can produce this problem, but I'm not sure.

About the synchronized: the problem is that doWrite would be possibly be called in two threads, something like this:

// asynchronously called by Jetty
onWritePossible()
{
  doWrite();
}

// asynchronously called by possibly other threads
onDataGenerated(byte [] data)
{
   synchronized(this)
  {
     _buffer.put(data);
    doWrite(); 
  } 
}

I need to doWrite in two places, because there are two situations: 
1) when onWritePossible() is called by Jetty, but the application may not have any data to write (i.e. _os.isReady() returns true, but _buffer.hasRemaining() returns false); so when onDataGenerated() is called, it has to attempt to write because otherwise onWritePossible() won't be called again; so this write could happen in application threads
2) when onDataGenerated() is called, but _os.isReady() returns false, the data would be buffered; later Jetty would invoke onWritePossible(); it has to attempt to write there because there can be data in buffer, and it cannot wait to invoke doWrite() inside onDataGenerated(), because onDataGenerated() may not be invoked again (e.g. it was the last invocation); the the write could happen in Jetty threads

Because there can be two threads attempting to invoke doWrite(), I think some locking is needed. Do you have any suggestions on a better approach to solve the problem?

Btw, is it assumed that write() must happen inside onWritePossible()? Could this be the problem? At least in most example code I saw write() happens inside onWritePossible().

Thanks,
Michael

On Tue, Apr 14, 2015 at 2:02 PM, Simone Bordet <sbordet@xxxxxxxxxxx> wrote:
Michael,

On Tue, Apr 14, 2015 at 7:54 PM, Michael Aaron <maaaroooon@xxxxxxxxx> wrote:
> Hello,
>
> I have upgraded to jetty-all-9.2.10.v20150310, but the problem remains. What
> might be wrong? Does this exception mean usage error (my code attempting to
> write when isReady() is not true), or does this mean some internal problem
> of Jetty?

Two things:

1) can you replicate the issue with the latest (built from the master
branch) Jetty ?
2) can you put up a reproducible test case ?

About your code, the use of synchronized is not optimal for async I/O
usage (you really want to be lock free for async I/O).

Your code looks ok, but it's incomplete for us to give you a full
picture. We would need onWritePossible() and understand when doWrite()
is called.
What Joakim was referring to is one of the issue I mention in the
slides, but you are avoiding it by testing again _os.isReady() in the
while _expression_, so the buffer is not corrupted.

Could be a 9.2.x issue, that's why if you can test with 9.3.x (master
branch) will be great.

--
Simone Bordet
----
http://cometd.org
http://webtide.com
http://intalio.com
Developer advice, training, services and support
from the Jetty & CometD experts.
Intalio, the modern way to build business applications.
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users


Back to the top