Skip to content

fix: net requests failing in utility process after network service re… - #49215

Closed
loufultoncz-coder wants to merge 9 commits into
electron:mainfrom
loufultoncz-coder:fix/electron/net
Closed

loufultoncz-coder wants to merge 9 commits into
electron:mainfrom
loufultoncz-coder:fix/electron/net

Conversation

@loufultoncz-coder

@loufultoncz-coder loufultoncz-coder commented Dec 15, 2025 •

Copy link
Copy Markdown
Contributor

Description of Change

Fix an issue where the net module in the utility process fails to send any network requests after the Network Service process crashes and is restarted.

The utility process caches a URLLoaderFactory instance that becomes invalid once the Network Service is recreated. Since the utility process is not restarted and the cached factory is not refreshed, all subsequent net requests fail.

This change ensures that the cached URLLoaderFactory is properly reset and rebound when the Network Service connection becomes invalid, allowing network requests to recover automatically without requiring a utility process restart.

Checklist

Release Notes

Notes: Fixed an issue where net requests could fail permanently after the Network Service process crashed and restarted.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Dec 15, 2025
@deepak1556
deepak1556 self-requested a review December 15, 2025 11:54

@deepak1556 deepak1556 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great catch! would need some refactor around re-creating the factory, additionally some high level questions

  1. What error codes do the active requests get when network process crashes
  2. What does the renderer process do today when it detects the network process crashes, does it also reset the factories ?
  3. Is there a test case that we can add as part of the PR ?

mojo::GenericPendingReceiver receiver) {
if (auto r = receiver.As<network::mojom::URLLoaderFactory>()) {
LOG(INFO) << "utility process bind network::mojom::URLLoaderFactory";
mojo::PendingRemote<network::mojom::URLLoaderFactory> url_loader_factory;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. There is duplication of the factory params here and in api::UtilityProcessWrapper
  2. We are not passing the URLLoaderNetworkObserver associated with the utility process anymore which would break login events after restart

Both of these can be solved by extracting the api::UtilityProcessWrapper in ElectronBrowserClient::BindUtilityHostReceiver with base::ProcessId via the global map maintained currently api::UtilityProcessWrapper::FromProcessId. But to get base::ProcessId we need to adjust the callsite https://source.chromium.org/chromium/chromium/src/+/main:content/browser/service_host/utility_process_host_receiver_bindings.cc;l=43 to also pass the content::UtilityProcessHost then the associated process id can be extracted from content::BrowserChildProcessHost via process_->GetData().GetProcess()

Comment thread shell/services/node/node_service.cc Resolved
@loufultoncz-coder

loufultoncz-coder commented Dec 16, 2025 •

Copy link
Copy Markdown
Contributor Author

Great catch! would need some refactor around re-creating the factory, additionally some high level questions

  1. What error codes do the active requests get when network process crashes
  2. What does the renderer process do today when it detects the network process crashes, does it also reset the factories ?
  3. Is there a test case that we can add as part of the PR ?

Hi @deepak1556 , thank you for raising these questions — I’ve looked into the current behavior and wanted to share what I found:

  1. Error codes on active requests when the network process crashes

When the network process crashes, in-flight requests are aborted and typically surface as generic network failures (e.g. ERR_FAILED / ERR_ABORTED) to the caller. The exact error depends on the request state at the time of the crash, but there is no graceful recovery for active requests today — they fail and need to be re-issued once the network service is back.

  1. Renderer behavior on network process crash

On the renderer side, this is handled in
content/browser/renderer_host/render_frame_host_impl.cc.

RenderFrameHostImpl::CreateNetworkServiceDefaultFactoryAndObserve
listens for UpdateSubresourceLoaderFactories and updates the renderer
with new network service factories when the network process crashes
and restarts.

This ensures renderer-side network interfaces are re-bound via Mojo.

  1. Test coverage

There isn’t currently a targeted test covering utility/network process
crash combined with factory re-creation for this path. I agree it would
be valuable to add coverage here. I’m looking into whether we can add a
browser-level test that simulates a network process crash and verifies
factory re-initialization as part of this PR, or otherwise follow it up
with a dedicated test CL.

@deepak1556

Copy link
Copy Markdown
Member

Thanks for the followup,

  1. I like the approach with UpdateSubresourceLoaderFactories based on the disconnect handler from the network service, could we do something similar on the api::UtilityProcessWrapper but in our case register a hook to network process health via content::RegisterNetworkServiceProcessGoneHandler then we send the new factories to the node service from the browser side rather than the making a request from service side.

@loufultoncz-coder

Copy link
Copy Markdown
Contributor Author

Thanks for the followup,

  1. I like the approach with UpdateSubresourceLoaderFactories based on the disconnect handler from the network service, could we do something similar on the api::UtilityProcessWrapper but in our case register a hook to network process health via content::RegisterNetworkServiceProcessGoneHandler then we send the new factories to the node service from the browser side rather than the making a request from service side.

Thanks for your feedback!

It seems that content::RegisterNetworkServiceProcessGoneHandler is primarily intended for internal use within the content module and is not publicly exposed via content/public/browser/network_service_instance.h.

After considering other alternatives, I opted for current change as a minimal and effective approach.

@deepak1556

Copy link
Copy Markdown
Member

You can use exported functions from content/browser/network_service_instance_impl.h but will need a nogncheck which is fine for this case. It also exposes the testing helpers to restart the network service, we should definitely use it to write a test, the testing helpers can be exposed via https://github.com/electron/electron/blob/main/shell/common/api/electron_api_testing.cc which is an internal module.

@loufultoncz-coder

Copy link
Copy Markdown
Contributor Author

You can use exported functions from content/browser/network_service_instance_impl.h but will need a nogncheck which is fine for this case. It also exposes the testing helpers to restart the network service, we should definitely use it to write a test, the testing helpers can be exposed via https://github.com/electron/electron/blob/main/shell/common/api/electron_api_testing.cc which is an internal module.

Thanks for the suggestion. I’ve updated the logic following this approach, and I plan to add the unit tests tomorrow.

@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Dec 22, 2025
@loufultoncz-coder

Copy link
Copy Markdown
Contributor Author

@deepak1556 Thank you for pointing this out.

While investigating this issue, I noticed that the same problem also exists in the browser process — the cached URLLoaderFactory can become invalid after the Network Service restarts, leading to similar request failures.

I’ve addressed this as well in the latest commit, where the browser-side factory is reset and rebound when the Network Service connection is lost, so requests can recover correctly without requiring a process restart.

Please let me know if this approach looks reasonable to you, or if you’d prefer handling the browser and utility processes differently. Happy to make adjustments based on your feedback.

@loufultoncz-coder

Copy link
Copy Markdown
Contributor Author

Hi @deepak1556

I’ve added a new test case to address the issue we discussed earlier. Could you please take another look when you have a moment? Your feedback would be much appreciated. Let me know if you have any questions or need further changes!

Thanks in advance!

@codebytere
codebytere requested a review from deepak1556 January 13, 2026 14:08
@loufultoncz-coder

Copy link
Copy Markdown
Contributor Author

Hi @deepak1556 , I noticed this PR has been open for a while, can you take a look when you have time? Thanks!

@deepak1556

Copy link
Copy Markdown
Member

Apologies for the delay, the PR is on the top of my list to review for this week.

@deepak1556

Copy link
Copy Markdown
Member

@loufultoncz-coder the changes were revisited as part of #49887. Thank you for your contribution, we will ensure to capture it in our release notes.

@deepak1556 deepak1556 closed this Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants