AI Briefing
KO

WSL2 Terminal Freezing 20 Seconds After Closing, Solved with PowerShell Background Execution

·2023.05.31 08:00

Key point

The issue where a service stops about 20 seconds after closing the WSL2 terminal window was resolved by running it in the background via PowerShell.

Details

WSL2 Version Update and Docker Environment Issues

Netmarble's Technology Management Team and Architecture Optimization Team shared an issue that occurred in a WSL2-based Docker development environment. Previously used batch files failed to run, and the issue persisted even when renaming the nohup.out file. This was analyzed as being due to differences caused by a WSL version update. Between the old version (default Windows configuration) and the new version (installed via Microsoft Store), the wsl.exe and Linux kernel versions differ, and Docker daemon host configuration is only supported from kernel version 5.15 onward.

WSL State Change Phenomenon When Closing the Terminal

When the WSL connection window was closed, the WSL state changed from Running to Stopped after about 20 seconds. This phenomenon appeared after a Windows update; while it remained an exception in the Running state when web servers such as NGINX or APACHE were running, in a typical Docker environment the service would stop. Even when attempting background execution using the nohup command together with &, the problem where WSL still shut down after about 20 seconds was not resolved.

Resolution via PowerShell Background Execution

The key solution is to keep the WSL execution window itself running in the background. Using PowerShell's start-process command with the -WindowStyle Hidden option to run WSL in a hidden window allows the service to continue even after the terminal is closed. In the final batch file, after the netsh interface portproxy configuration, powershell.exe -Command "start-process wsl.exe -WindowStyle Hidden" was added as the last line, replacing nohup. This approach allows a stable development environment to be configured for accessing the Docker daemon from Windows without needing to keep the terminal window open.

This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.

Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.