2021-01-29

WIldfly / Undertow UT010029 Stream is closed

running Wildfly 16 on jdk 9 and when repeatedly calling java StringReader, I get UT010029 Stream is closed.

public void export(OutputStream out) throws Exception   {
...
while() { 
  ...
  csvstream = new StringReader(csvcontent.toString());
  try { 
    while ((iRead = csvstream.read()) != -1) out.write(iRead);
    out.flush();
  } catch(IOException e)    { 
    validconnection=false;
    log.error(e);
    e.printStackTrace();
    break;      
  } finally {if (csvstream != null) csvstream.close();}
}

the error happens on csvstream.read()

java.io.IOException: UT010029: Stream is closed
at io.undertow.servlet.spec.ServletOutputStreamImpl.write(ServletOutputStreamImpl.java:137)
at io.undertow.servlet.spec.ServletOutputStreamImpl.write(ServletOutputStreamImpl.java:122)

I've verified csvstream is not null, but is closed and csvcontent is not null and has a positive length. Sometimes it runs through all the iterations no problem, sometimes it errors out.

It looks like maybe "out" is the stream that is closed. The offending line in ServletOutputStreamImpl.java is:

if (anyAreSet(state, FLAG_CLOSED) || servletRequestContext.getOriginalResponse().isTreatAsCommitted()) {
      throw UndertowServletMessages.MESSAGES.streamIsClosed();

In my case, out is passed in as a parameter. The calling party being a servlet like so:

OutputStream out = response.getOutputStream(  );
if (ve!=null)   {
  try {
        ve.export(out);
    } catch (Exception e)   {
        e.printStackTrace();
    }
} //if ve!=null

ve is a simple POJO.

Any help with this would be appreciated! Thanks.



from Recent Questions - Stack Overflow https://ift.tt/3iXZTTz
https://ift.tt/eA8V8J

No comments:

Post a Comment