【问题标题】:WIldfly / Undertow UT010029 Stream is closedWIldfly / Undertow UT010029 流已关闭
【发布时间】:2021-05-02 22:19:20
【问题描述】:

在 jdk 9 上运行 Wildfly 16,当反复调用 java StringReader 时,我得到 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();}
}

错误发生在 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)

我已验证 csvstream 不为空,但已关闭且 csvcontent 不为空且长度为正。 有时它运行所有迭代都没问题,有时它会出错。

看起来“out”可能是关闭的流。 ServletOutputStreamImpl.java 中的违规行是:

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

在我的例子中,out 作为参数传入。调用方是这样的 servlet:

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

ve 是一个简单的 POJO。

对此的任何帮助将不胜感激! 谢谢。

【问题讨论】:

    标签: java wildfly java-io undertow


    【解决方案1】:

    以防万一其他人遇到此问题 - 这已通过 Standalone.xml 的 Wildfly 配置解决: http-listener 元素具有属性 read-timeout 和 write-timeout。 Wildfly 的最新版本限制了默认值,并且这些属性未在默认的standalone.xml 中指定。 见:

    [Wildfly 模型参考][1]

    【讨论】:

      猜你喜欢
      • 2018-07-17
      • 2015-05-31
      • 1970-01-01
      • 1970-01-01
      • 2021-06-19
      • 2016-10-24
      • 2014-10-26
      • 2019-09-23
      • 2018-02-05
      相关资源
      最近更新 更多