Skip to content

feat: Use Electron's net module as the default HTTP transport - #2027

Open
joker23 wants to merge 5 commits into
mainfrom
skz/electron-sdk-next-net-module
Open

joker23 wants to merge 5 commits into
mainfrom
skz/electron-sdk-next-net-module

Conversation

@joker23

@joker23 joker23 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

This PR will make it so that electron sdk will use the native net module as the default HTTP transport.

addresses:

  • SDK-2274

Note

Overview
The Electron SDK’s platform HTTP layer now routes polling, analytics, diagnostics, and streaming through Electron’s net.fetch (Chromium’s stack) instead of Node http/https plus a custom response wrapper. ElectronRequests waits for app.whenReady(), applies caller timeouts via AbortController, keeps non-streaming requests on redirect: 'error' with credentials: 'omit' and cache: 'no-store', and uses a dedicated streaming path that **follow**s redirects and forces accept-encoding: identity.

createEventSource is wired to @launchdarkly/eventsource (replacing launchdarkly-eventsource) and reuses streaming fetch. ElectronResponse and HeaderWrapper are removed because responses are standard Fetch API objects.

Tests add Electron mocks, streaming/SSE/timeout/redirect coverage, and client close() cleanup so Jest can exit; HeaderWrapper tests are dropped with the deleted type.

Reviewed by Cursor Bugbot for commit 2d15645. Bugbot is set up for automated code reviews on this repo. Configure here.

@joker23
joker23 added this pull request to stack #2019 September 16, 2026 20:26
@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 19243 bytes
Compressed size limit: 33000
Uncompressed size: 106351 bytes

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 34596 bytes
Compressed size limit: 35500
Uncompressed size: 123487 bytes

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 26376 bytes
Compressed size limit: 44000
Uncompressed size: 171444 bytes

@joker23
joker23 force-pushed the skz/electron-sdk-next-net-module branch 2 times, most recently from 7032cb2 to c4b16bd Compare September 16, 2026 20:54
Comment on lines +67 to +69
redirect: 'error',
credentials: 'omit',
cache: 'no-store',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would like some opinions on this one. I personally don't see a reason to deviate from current behavior (what we have in nodes http/https implementation)

@joker23
joker23 force-pushed the skz/electron-sdk-next-net-module branch 3 times, most recently from e974fde to 86efe47 Compare September 17, 2026 13:57
Base automatically changed from skz/electron-sdk-next-move-example to main September 22, 2026 15:56
@joker23
joker23 force-pushed the skz/electron-sdk-next-net-module branch from 86efe47 to a023721 Compare September 22, 2026 15:57
@joker23
joker23 force-pushed the skz/electron-sdk-next-net-module branch 4 times, most recently from 10e1865 to cdaba41 Compare October 29, 2026 14:34
@joker23
joker23 force-pushed the skz/electron-sdk-next-net-module branch from cdaba41 to 36be846 Compare November 19, 2026 18:24
@joker23
joker23 marked this pull request as ready for review November 20, 2026 16:46
@joker23
joker23 requested a review from a team as a code owner November 20, 2026 16:46

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

Devin Review

req.on('error', (err) => {
reject(err);
try {
return await net.fetch(url, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Discarded error responses retain open connections

When error bodies exceed stream buffers, fetch leaves discarded responses paused. makeRequestor discards unsuccessful bodies, and EventSender never reads bodies. Unlike the former eagerly drained responses, these retain connections across retries.

Learn more

The previous response wrapper started reading every response immediately, including bodies callers ignored. Electron's native fetch instead exposes a backpressured body stream. The polling requestor reads only successful responses, and the event sender only inspects status and headers. An ignored body larger than the stream buffers pauses the underlying read. Electron pins its native URL loader until completion or cancellation, so garbage collection does not release that paused request. Polling retries can then create additional requests without releasing previous ones.

Example: A configured relay returns HTTP 500 with a 512 KiB diagnostic page. Polling rejects the status without reading or cancelling the page. The response pauses once its buffers fill, and the next poll opens another request while the previous loader remains retained.

Recommended fix: Preserve eager, rejection-safe response consumption for non-streaming requests, or explicitly cancel every response body that polling and event delivery discard. Keep the streaming path unbuffered. Add a regression test using a finite error body larger than the stream buffers and verify that the request completes or cancels after the caller ignores its body.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +4 to +14
// electron.net isn't available outside a real Electron main process. net.fetch is a standard
// fetch over Chromium's stack, so Node's own fetch stands in for it. Both decode a compressed
// body and keep the origin's content-encoding header.
jest.mock('electron', () => ({
app: {
isReady: jest.fn(() => true),
whenReady: jest.fn(() => Promise.resolve()),
},
net: {
fetch: jest.fn((url: string, init: RequestInit) => globalThis.fetch(url, init)),
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Native Electron transport remains untested

The net.fetch mock exercises Node fetch, not Chromium networking. REPORT requests, decompression, redirects, and cancellation lack native-runtime coverage. Electron integration tests remain necessary to validate those transport assumptions.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@joker23
joker23 force-pushed the skz/electron-sdk-next-net-module branch from b2ba260 to 2d15645 Compare November 20, 2026 16:50
@cursor cursor Bot added the risk:medium label Nov 20, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: medium.

Automated risk review (dry run): Medium

This PR would not be automatically approved. Human approval required.

Why: This replaces the Electron SDK HTTP stack in ElectronRequests.ts (Node http/https to Electron net.fetch, streaming redirect handling, and the eventsource dependency), which is a bounded but meaningful behavior change. Cursor Bugbot was still pending after the wait window, so the automated reviewer signal is incomplete; human review is needed and no reviewers were assigned.

If you disagree with this review, share this PR in #feedback-agent-approvals or submit a changes-requested review explaining why.

Open in Web View Automation 

Sent by Cursor Approval Agent: Dry-Run PR Approver

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant