java.lang.Object
net.i2p.util.SimpleTimer2.TimedEvent
net.i2p.i2ptunnel.I2PTunnelHTTPServer.BodyWatchdog
All Implemented Interfaces:
Runnable
Enclosing class:
I2PTunnelHTTPServer

private static final class I2PTunnelHTTPServer.BodyWatchdogextends SimpleTimer2.TimedEvent
Watchdog for an async (detached) body handoff. After I2PTunnelHTTPServer.handOffBody(ThreadPoolExecutor, I2PTunnelHTTPServer.Sender, String) queues the Server-to-Client Sender and the handler thread returns, nothing supervises the pool worker: a browser that stops reading pins it in a blocked write indefinitely (socket soTimeout bounds reads only). This periodic event polls the Sender's last-read stamp and, once no progress is made for I2PTunnelHTTPServer.ioStallTimeoutMs, closes the streams to unblock the worker and runs the idempotent finish so the connection is torn down exactly once. Polling is every 5s, the SimpleTimer2 minimum; detection therefore lands within one poll of the stall window.
  • Field Details

    • POLL_MS

      private static final long POLL_MS
      SimpleTimer2 rejects periods below 5s.
      See Also:
    • _body

      private final I2PTunnelHTTPServer.Sender _body
      The sender copying the request body.
    • _finished

      private final AtomicBoolean _finished
      Set when the copy is finished.
    • _finish

      private final Runnable _finish
      Callback run when the copy finishes.
    • _browserin

      private final InputStream _browserin
      The browser's input stream.
    • _browserout

      private final OutputStream _browserout
      The browser's output stream.
    • _serverin

      private final InputStream _serverin
      The web server's input stream.
    • _serverout

      private final OutputStream _serverout
      The web server's output stream.
    • _log

      private final Log _log
      Logger for this copy.
  • Constructor Details

    • BodyWatchdog

      BodyWatchdog(I2PTunnelHTTPServer.Sender body, AtomicBoolean finished, Runnable finish, InputStream browserin, OutputStream browserout, InputStream serverin, OutputStream serverout, Log log)
      Watches a stalled response body and aborts the connection.
      Parameters:
      body - the detached Server-to-Client Sender being supervised
      finished - request-wide finish-once flag
      finish - idempotent finish to run once a stall is confirmed
      browserin - browser-side request stream; may be null
      browserout - browser-side response stream; may be null
      serverin - I2P-side response body stream; may be null
      serverout - I2P-side request stream; may be null
      log - may be null
  • Method Details

    • timeReached

      public void timeReached()
      Description copied from class: SimpleTimer2.TimedEvent
      Called when this event's scheduled time arrives. Must NOT block. For periodic events, call schedule(period) at the end to self-reschedule.
      Specified by:
      timeReached in class SimpleTimer2.TimedEvent