Skip to content

Chat-path /imagegen outer catch missing abort guard bogus error log + write to closed socket #275

Description

@Sertug17

Bug

The chat-path /imagegen command handler (the one that wraps image generation as a synthetic chat completion) creates an imagegenAbort AbortController and correctly passes its signal to payFetch and the poll loop. But the outer catch (err) at line 4300 does not check imagegenAbort.signal.aborted before logging and writing the error response.

When the client disconnects mid-generation, the AbortError propagates to this catch, logs a spurious [ClawRouter] /imagegen error: The operation was aborted and attempts res.writeHead(500) on the already-closed socket.

Current code (line 4300)

} catch (err) {
  const errMsg = err instanceof Error ? err.message : String(err);
  console.error(`[ClawRouter] /imagegen error: ${errMsg}`);
  if (!res.headersSent) {
    res.writeHead(500, ...);

Expected (matches chat-path /img2img at line 4512)

} catch (err) {
  if (imagegenAbort.signal.aborted) return; // client gone nothing to report
  const errMsg = err instanceof Error ? err.message : String(err);
  console.error(`[ClawRouter] /imagegen error: ${errMsg}`);

Working references

  • API-path image gen catch (line 2808): if (clientAbort.signal.aborted) return;
  • Chat-path /img2img catch (line 4512): if (img2imgAbort.signal.aborted) return;
  • API-path img2img catch (line 2952): if (clientAbort.signal.aborted) return;

Impact

Bogus error log noise on every client disconnect during /imagegen. Attempted write to closed socket (silently fails due to !res.headersSent guard, but the log line is still wrong).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions