github/copilot-sdk · error · IOException

Interrupted while waiting for callback data

Error message

Interrupted while waiting for callback data

What it means

QueueInputStream backs its blocking read with a LinkedBlockingQueue fed by an async callback. When the reading thread is interrupted while blocked in queue.take(), the stream restores the interrupt flag and wraps the InterruptedException in an IOException with this message, since InputStream cannot throw InterruptedException directly.

Solutions

  1. Handle the IOException and check Thread.currentThread().isInterrupted() to confirm interruption, then abort the read operation gracefully.
  2. If interruption was accidental, remove the interrupt source or ensure no other task shares the reading thread.
  3. Structure shutdown so reads finish (close the stream / deliver EOF_SENTINEL via close()) before interrupting the thread.
  4. Propagate the interrupt state (already preserved by the stream) and retry only if your cancellation policy expects it.

Example fix

// before
int b = queueStream.read(); // IOException on interrupt

// after
try {
    int b = queueStream.read();
} catch (IOException e) {
    if (Thread.currentThread().isInterrupted()) {
        throw new CancellationException("read interrupted");
    }
    throw e;
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
    int b = queueStream.read();
} catch (IOException e) {
    if (Thread.currentThread().isInterrupted()) {
        // interruption during queue.take(): treat as cancellation
        cleanup();
        return; // or rethrow as InterruptedException/CancellationException
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling read() on a QueueInputStream while another thread interrupts the reading thread — typically during executor shutdownNow(), task cancellation, or a timeout mechanism that interrupts worker threads.

Common situations: Cancelling a streaming read via Future.cancel(true); shutting down a thread pool with shutdownNow() while a read is pending; application shutdown paths interrupting I/O threads; timeout watchdogs interrupting stalled reads.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/d7b945b165a707e7. Report an issue: GitHub.

Appendix: source

Thrown at java/sdk/src/main/java/com/github/copilot/ffi/QueueInputStream.java:85

    public int read(byte[] b, int off, int len) throws IOException {
        Objects.requireNonNull(b, "buffer must not be null");
        if (off < 0 || len < 0 || off + len > b.length) {
            throw new IndexOutOfBoundsException("Invalid off/len for buffer of length " + b.length);
        }
        if (len == 0) {
            return 0;
        }
        if (eof) {
            return -1;
        }

        while (currentChunk == null || currentOffset >= currentChunk.length) {
            byte[] next;
            try {
                next = queue.take();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new IOException("Interrupted while waiting for callback data", e);
            }
            if (next == EOF_SENTINEL) {
                eof = true;
                return -1;
            }
            if (next.length == 0) {
                continue;
            }
            currentChunk = next;
            currentOffset = 0;
        }

        int available = currentChunk.length - currentOffset;
        int toCopy = Math.min(available, len);
        System.arraycopy(currentChunk, currentOffset, b, off, toCopy);
        currentOffset += toCopy;
        return toCopy;
    }

View on GitHub (pinned to cd8cf15dc3)