Fix SubprocVecEnv ConnectionResetError with forkserver/spawn#668
Merged
eleurent merged 1 commit intoApr 7, 2026
Merged
Conversation
Make _register_highway_envs() idempotent so re-importing highway_env in a forkserver/spawn subprocess does not raise a duplicate-registration error. Add a gymnasium entry-point declaration for future auto-discovery. Add 12 multiprocessing tests covering forkserver and spawn start methods across 6 environment IDs. Fixes Farama-Foundation#648 Signed-off-by: Lidang-Jiang <lidangjiang@gmail.com>
eleurent
approved these changes
Apr 7, 2026
Collaborator
|
Neat, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
ConnectionResetError: [Errno 104] Connection reset by peerwhen creating highway-env environments viaSubprocVecEnv(stable-baselines3) or any multiprocessing wrapper that uses theforkserver/spawnstart method.Root cause:
SubprocVecEnvdefaults toforkserverwhen available. Child processes started viaforkserverorspawndo not inherit the parent'simport highway_env, sogymnasium.register()calls inhighway_env/__init__.pynever execute in the subprocess. Whengym.make("highway-fast-v0")runs in the child, the environment is not in the registry →NameNotFound→ subprocess crash →ConnectionResetErrorin the parent.Fix:
_register_highway_envs()idempotent (skip if already registered) so that re-importinghighway_envvia gymnasium'smodule:env_nameresolution does not raise duplicate-registration errorspyproject.tomlfor potential future auto-discoverygym.make("highway_env:highway-fast-v0")(with module prefix) when usingSubprocVecEnv— gymnasium's_find_specimports the module in the subprocess before looking up the environmentFixes #648
Before
After
Test plan
forkserverandspawn× 6 env IDsSubprocVecEnvwithstable-baselines3works end-to-end