Opened 3 years ago

Closed 3 years ago

#2273 closed defect (fixed)

Stopping a torrent while I2PSnark is allocating space causes out of bounds exception

Reported by: Reportage Owned by: zzz
Priority: minor Milestone: 0.9.36
Component: apps/i2psnark Version: 0.9.34
Keywords: i2psnark, file allocation, out of bounds exception Cc:
Parent Tickets: Sensitive: no


java.lang.IndexOutOfBoundsException: Illegal Request (6119,262144,1)
     at org.klomp.snark.Request.<init>(
     at org.klomp.snark.PeerState.returnPartialPieces(
     at org.klomp.snark.Peer.disconnect(
     at org.klomp.snark.PeerCoordinator.halt(
     at org.klomp.snark.Snark.stopTorrent(
     at org.klomp.snark.Snark.stopTorrent(
     at org.klomp.snark.SnarkManager.stopTorrent(
     at org.klomp.snark.web.I2PSnarkServlet.processRequest(
     at org.klomp.snark.web.I2PSnarkServlet.doGetAndPost(
     at org.klomp.snark.web.I2PSnarkServlet.doPost(
     at javax.servlet.http.HttpServlet.service(
     at javax.servlet.http.HttpServlet.service(
     at org.eclipse.jetty.servlet.ServletHolder.handle(
     at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(
     at net.i2p.servlet.filters.XSSFilter.doFilter(
     at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(
     at org.eclipse.jetty.servlet.ServletHandler.doHandle(
     at org.eclipse.jetty.server.handler.ScopedHandler.handle(
     at org.eclipse.jetty.server.session.SessionHandler.doHandle(
     at org.eclipse.jetty.server.handler.ContextHandler.doHandle(
     at org.eclipse.jetty.servlet.ServletHandler.doScope(
     at org.eclipse.jetty.server.session.SessionHandler.doScope(
     at org.eclipse.jetty.server.handler.ContextHandler.doScope(
     at org.eclipse.jetty.server.handler.ScopedHandler.handle(
     at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(
     at org.eclipse.jetty.servlets.gzip.GzipHandler.handle(
     at net.i2p.router.web.HostCheckHandler.handle(
     at org.eclipse.jetty.server.handler.HandlerCollection.handle(
     at org.eclipse.jetty.server.handler.HandlerWrapper.handle(
     at org.eclipse.jetty.server.Server.handle(
     at org.eclipse.jetty.server.HttpChannel.handle(
     at org.eclipse.jetty.server.HttpConnection.onFillable(
     at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(
     at org.eclipse.jetty.util.thread.QueuedThreadPool$


Change History (7)

comment:1 Changed 3 years ago by zzz

Milestone: undecided0.9.36
Status: newaccepted


comment:2 Changed 3 years ago by Zlatin Balevsky

Why are there any peers connected before the storage is allocated? I haven't seen any other torrent clients do this. This was most probably an incoming connection and I'm also going to guess the torrent was started and stopped repeatedly. Regardless, snark should not allow any incoming connections until the storage is allocated.

comment:3 Changed 3 years ago by Zlatin Balevsky

If I'm right about it being started and stopped repeatedly, then the following is possible:

  1. Torrent was started, and it's infohash added to the PeerCoordinatorSet
  2. An incoming connection arrived and a new thread to handle it was started in ConnectionAcceptor line 200
  3. Before that thread was able to do anything, the torrent was stopped and started again, removing the infohash from PeerCoordinatorSet but then re-adding it
  4. The thread started in step 2 resumed operation and processed the incoming request, finding the infohash and adding the peer to the list
  5. Torrent was stopped again and bang!

comment:4 Changed 3 years ago by zzz

I'm working on a different theory.

@OP if you remember which torrent it was, can you confirm the piece size for it was 256 KB?

comment:5 Changed 3 years ago by Reportage

I can confirm that I can reliably reproduce the error with torrents with a 256K piece size. Steps to reproduce:

  • Start torrent
  • Wait for "allocating" to appear on main torrent page
  • Hit the Stop button

As an observation, it appears that, despite knowing the size of the torrent, the allocation doesn't take place until peer(s) have connected and start uploading.

comment:6 Changed 3 years ago by zzz

I asked about piece size not because any particular piece size is problematic. I was trying to correlate the first line of the error:

java.lang.IndexOutOfBoundsException: Illegal Request (6119,262144,1)

with the piece size. So my question is, is the second number above (262144) equal to the piece size of the torrent being stopped?

Also, indeed, we don't allocate files until necessary, maybe that makes snark different than any other BT client, but it's not inherently a problem. And for magnets, you don't have a choice but to connect to peers first.

comment:7 Changed 3 years ago by zzz

Resolution: fixed
Status: acceptedclosed

Fixed in d12c13d4e0e99c025a92c156e28f592e5b1ac9a7 0.9.35-5
Was caused by lazy reuse of Request class with a length of 1 on a completed piece. Added new constructor to fix it.
Due to locking, after clicking stop, page will not load until allocation is complete. That's the best I can do.

Note: See TracTickets for help on using tickets.