Menu

#382 Statement close return Exception: java.net.SocketException: sendto failed: EBADF (Bad file number)

jtopenlite
closed-out-of-date
None
1
2017-09-14
2017-02-03
No

Hello
on Android <5.1 everything works fine, while on Android 5.1 using the library jtopenlite

Statement st = conn.createStatement();
String sql = "....";
ResultSet rs = st.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
while (rs.next()) {
...
}

--> conn.close(); this row trows the following exception

E/System: Uncaught exception thrown by finalizer
02-03 06:22:29.789 4516-4531/it.sued.suedtotem E/System: java.net.SocketException: sendto failed: EBADF (Bad file number)
at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:546)
at libcore.io.IoBridge.sendto(IoBridge.java:515)
at java.net.PlainSocketImpl.write(PlainSocketImpl.java:504)
at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:37)
at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:266)
at java.io.BufferedOutputStream.flushInternal(BufferedOutputStream.java:185)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:85)
at java.io.FilterOutputStream.close(FilterOutputStream.java:61)
at java.io.BufferedOutputStream.close(BufferedOutputStream.java:152)
at com.ibm.jtopenlite.HostServerConnection$HostOutputStream.close(HostServerConnection.java:769)
at com.ibm.jtopenlite.HostServerConnection.forceClose(HostServerConnection.java:123)
at com.ibm.jtopenlite.HostServerConnection.close(HostServerConnection.java:113)
at com.ibm.jtopenlite.HostServerConnection.finalize(HostServerConnection.java:148)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:191)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:174)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.ErrnoException: sendto failed: EBADF (Bad file number)
at libcore.io.Posix.sendtoBytes(Native Method)
at libcore.io.Posix.sendto(Posix.java:206)
at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:278)
at libcore.io.IoBridge.sendto(IoBridge.java:513)
at java.net.PlainSocketImpl.write(PlainSocketImpl.java:504) 
at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:37) 
at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:266) 
at java.io.BufferedOutputStream.flushInternal(BufferedOutputStream.java:185) 
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:85) 
at java.io.FilterOutputStream.close(FilterOutputStream.java:61) 
at java.io.BufferedOutputStream.close(BufferedOutputStream.java:152) 
at com.ibm.jtopenlite.HostServerConnection$HostOutputStream.close(HostServerConnection.java:769) 
at com.ibm.jtopenlite.HostServerConnection.forceClose(HostServerConnection.java:123) 
at com.ibm.jtopenlite.HostServerConnection.close(HostServerConnection.java:113) 
at com.ibm.jtopenlite.HostServerConnection.finalize(HostServerConnection.java:148) 
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:191) 
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:174) 
at java.lang.Thread.run(Thread.java:818) 

Discussion

  • John Eberhard

    John Eberhard - 2017-02-03
    • assigned_to: John Eberhard
     
  • John Eberhard

    John Eberhard - 2017-02-03

    Seems like an android related problem to me. I'm not sure why the finalizer thread is being run at close time. It should be run at some point after the close completes. After the closes completes, the stack should not look like the above since the closed flag is set in the HostServerConnection object.

    Does the exception happen all the time or just intermittently? Do your application always call the close method before disposing of the connection object?

     
  • Giancarlo Baracchino

    The exception happens all the time.
    Our application call the close method before disposing the connection.

    The same code is working from 2 years on several Android devices with version < 5.1 .

    Kind regards

     
  • John Eberhard

    John Eberhard - 2017-04-17

    I don't understand how your conn.close() method could throw the indicated stack -- the conn.close() method isn't in the stack trace. Do you have any other clues as to what might be wrong.

     
  • John Eberhard

    John Eberhard - 2017-09-14
    • status: open --> closed-out-of-date
     
  • John Eberhard

    John Eberhard - 2017-09-14

    Closing old bug.

     

Log in to post a comment.

MongoDB Logo MongoDB