actions / actions/toolkit

Leaked socket in cache/internal/cacheHttpClient

Open
#1,702 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
5.9k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

https://github.com/actions/cache/pull/1217 attempted to work around a dangling socket, which became especially apparent when that action migrated to Node 20, as Node v20 started keeping connection alive by default.

This solution worked for actions/cache in the meantime, but caused downstream consumers of to implement the same logic to avoid hanging processes and generated similar issues, such as:

The leaked socket originates in cache/src/internal/cacheHttpClient:

  const uploadChunkResponse = await retryHttpClientResponse(
    `uploadChunk (start: ${start}, end: ${end})`,
    async () =>
      httpClient.sendStream(
        'PATCH',
        resourceUrl,
        openStream(),
        additionalHeaders
      )
  )

sendStream return a response, the body of must be consumed to avoid holding the event loop open.

Something like the following ought to do it:

  const uploadChunkResponse = await retryHttpClientResponse(
    `uploadChunk (start: ${start}, end: ${end})`,
    async () => {
      const response = await httpClient.sendStream(
        'PATCH',
        resourceUrl,
        openStream(),
        additionalHeaders
      )

      await response.readBody()

      return response
    }
  )

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in cache/src/internal/cacheHttpClient at the uploadChunk call to httpClient.sendStream and inspect how its response is handled. Ensure the response body is consumed before returning, then verify that cache uploads no longer leave a socket holding the event loop open.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.