NullPointerException in CoyoteOutputStream

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

NullPointerException in CoyoteOutputStream

Mark A. Claassen
We were doing some load testing and we started getting a NullPointerException at the stack trace below.  We don't get the NPE all the time, so I am guessing some of these objects got corrupted somehow.
One place the clear() method is called from is the recycle() method in the Response object from the same package.

Has anyone seen this before?  My Internet searches did not reveal any other reports of this.  Is this something that has already been fixed in the course of other changes?

The version of Tomcat is 9.0.12 and we are using the openSSL underneath all this.

Thanks,
Mark

---------------
 at org.apache.catalina.connector.CoyoteOutputStream.checkNonBlockingWrite(CoyoteOutputStream.java:134)
 at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:95)
 at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89)
 at dsi.core.io.ByteCounterOutputStream.write(ByteCounterOutputStream.java:37)

--------------- CoyoteOutputStream
    private boolean checkNonBlockingWrite() {
        boolean nonBlocking = !ob.isBlocking(); <-- Line 134
        if (nonBlocking && !ob.isReady()) {
            throw new IllegalStateException(sm.getString("coyoteOutputStream.nbNotready"));
        }
        return nonBlocking;
    }
--------------- CoyoteOutputStream
    /**
     * Clear facade.
     */
    void clear() {
        ob = null;
    }
--------------- CoyoteOutputStream
    @Override
    public void close() throws IOException {
        ob.close();
    }
---------------

Mark Claassen
Senior Software Engineer

Donnell Systems, Inc.
130 South Main Street
Leighton Plaza Suite 375
South Bend, IN  46601
E-mail: mailto:[hidden email]
Voice: (574)232-3784
Fax: (574)232-4014

Disclaimer:
The opinions provided herein do not necessarily state or reflect
those of Donnell Systems, Inc.(DSI). DSI makes no warranty for and
assumes no legal liability or responsibility for the posting.



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException in CoyoteOutputStream

calder
On Fri, Jun 12, 2020, 10:36 Mark A. Claassen <[hidden email]> wrote:

> We were doing some load testing and we started getting a
> NullPointerException at the stack trace below.  We don't get the NPE all
> the time, so I am guessing some of these objects got corrupted somehow.
> One place the clear() method is called from is the recycle() method in the
> Response object from the same package.
>
> Has anyone seen this before?  My Internet searches did not reveal any
> other reports of this.  Is this something that has already been fixed in
> the course of other changes?
>
> The version of Tomcat is 9.0.12 and we are using the openSSL underneath
> all this.
>
> ---------------
>  at
> org.apache.catalina.connector.CoyoteOutputStream.checkNonBlockingWrite(CoyoteOutputStream.java:134)
>  at
> org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:95)
>  at
> org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89)
>  at dsi.core.io
> .ByteCounterOutputStream.write(ByteCounterOutputStream.java:37)
>


Apologies ... but this doesn't look like a complete stack trace, to include
any "caused by" statements (and the originating statement)


------------ CoyoteOutputStream

>     private boolean checkNonBlockingWrite() {
>         boolean nonBlocking = !ob.isBlocking(); <-- Line 134
>         if (nonBlocking && !ob.isReady()) {
>             throw new
> IllegalStateException(sm.getString("coyoteOutputStream.nbNotready"));
>         }
>         return nonBlocking;
>     }
> --------------- CoyoteOutputStream
>     /**
>      * Clear facade.
>      */
>     void clear() {
>         ob = null;
>     }
> --------------- CoyoteOutputStream
>     @Override
>     public void close() throws IOException {
>         ob.close();
>     }
> ---------------
Reply | Threaded
Open this post in threaded view
|

RE: NullPointerException in CoyoteOutputStream

Mark A. Claassen
Thanks for the reply, and sorry for the confusion.  I catch the error in my code and format it in a custom way, which is why it may look a bit different than what you expect.
That was not the complete stack, but the top is the top, which implies that 'ob' is null

After the ByteCounterOutputStream line, there is more of my code until I eventually get to:
    HttpServlet.service(HttpServlet.java:660)
The ByteCounterOutputStream wraps the HttpServletResponse.getOutputStream() and the error occurs when it is trying to write to the stream.


My code has been relatively unchanged for years. Additionally, this load test has succeeded using this version of tomcat of 10,000s of iterations.  
However, maybe some once-in-a-million occurrence happened and corrupted at least of one instance of the CoyoteOutputStream?  
And then whenever one of these gets reused, I can't write to the output stream.

CoyoteOutputStream.checkNonBlockingWrite(CoyoteOutputStream.java:134)
CoyoteOutputStream.write(CoyoteOutputStream.java:95)
CoyoteOutputStream.write(CoyoteOutputStream.java:89)
ByteCounterOutputStream.write(ByteCounterOutputStream.java:37) <-- My code doing a write()

private boolean checkNonBlockingWrite() {
    boolean nonBlocking = !ob.isBlocking(); <-- 134 (NPE here implies ob is null)
    if (nonBlocking && !ob.isReady()) {
        throw new IllegalStateException(sm.getString("coyoteOutputStream.nbNotready"));
    }
    return nonBlocking;
}
public void write(byte[] b, int off, int len) throws IOException {
    boolean nonBlocking = checkNonBlockingWrite(); <-- 95
    ob.write(b, off, len);
    if (nonBlocking) {
        checkRegisterForWrite();
    }
}
public void write(byte[] b) throws IOException {
    write(b, 0, b.length); <-- 89
}

-----Original Message-----
From: calder <[hidden email]>
Sent: Friday, June 12, 2020 12:31 PM
To: Tomcat Users List <[hidden email]>
Subject: Re: NullPointerException in CoyoteOutputStream

On Fri, Jun 12, 2020, 10:36 Mark A. Claassen <[hidden email]> wrote:

> We were doing some load testing and we started getting a
> NullPointerException at the stack trace below.  We don't get the NPE
> all the time, so I am guessing some of these objects got corrupted somehow.
> One place the clear() method is called from is the recycle() method in
> the Response object from the same package.
>
> Has anyone seen this before?  My Internet searches did not reveal any
> other reports of this.  Is this something that has already been fixed
> in the course of other changes?
>
> The version of Tomcat is 9.0.12 and we are using the openSSL
> underneath all this.
>
> ---------------
>  at
> org.apache.catalina.connector.CoyoteOutputStream.checkNonBlockingWrite
> (CoyoteOutputStream.java:134)
>  at
> org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStr
> eam.java:95)
>  at
> org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStr
> eam.java:89)
>  at dsi.core.io
> .ByteCounterOutputStream.write(ByteCounterOutputStream.java:37)
>


Apologies ... but this doesn't look like a complete stack trace, to include any "caused by" statements (and the originating statement)


------------ CoyoteOutputStream

>     private boolean checkNonBlockingWrite() {
>         boolean nonBlocking = !ob.isBlocking(); <-- Line 134
>         if (nonBlocking && !ob.isReady()) {
>             throw new
> IllegalStateException(sm.getString("coyoteOutputStream.nbNotready"));
>         }
>         return nonBlocking;
>     }
> --------------- CoyoteOutputStream
>     /**
>      * Clear facade.
>      */
>     void clear() {
>         ob = null;
>     }
> --------------- CoyoteOutputStream
>     @Override
>     public void close() throws IOException {
>         ob.close();
>     }
> ---------------

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException in CoyoteOutputStream

Konstantin Kolinko
In reply to this post by Mark A. Claassen
пт, 12 июн. 2020 г. в 18:36, Mark A. Claassen <[hidden email]>:
>
> We were doing some load testing and we started getting a NullPointerException at the stack trace below.  We don't get the NPE all the time, so I am guessing some of these objects got corrupted somehow.
> One place the clear() method is called from is the recycle() method in the Response object from the same package.
>
> Has anyone seen this before?  My Internet searches did not reveal any other reports of this.  Is this something that has already been fixed in the course of other changes?
>
> The version of Tomcat is 9.0.12 and we are using the openSSL underneath all this.

Why not the current version (9.0.36)?

Also
https://cwiki.apache.org/confluence/display/TOMCAT/Troubleshooting+and+Diagnostics#TroubleshootingandDiagnostics-TroubleshootingunexpectedResponsestateproblems

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]