运行服务器后,Windows(或 WSL)不断阻止端口

运行服务器后,Windows(或 WSL)不断阻止端口

我在 Windows 10 (1809) 中的 WSL 中运行一些 nodejs、python 和 golang 服务器。在过去几周里,我遇到了一个特别令人恼火的行为,即我用于运行 Web 服务器的任何端口在后续重启时都会被阻止。即使在冷重启后,我也无法让我的服务器在同一端口上运行。运行netstat -a -q -n也不会在列表中显示这些端口。我检查了我的 Windows Defender 防火墙,也没有特定的规则会阻止端口。

为了显示:

  1. 我运行一个 npm 包storybook- 它在端口 9001 上启动一个 Web 服务器。
  2. 运行服务器并工作一段时间后,我关闭了它。
  3. 重新启动我的电脑。
  4. 我尝试再次运行服务器,但收到此错误:
Error: listen EACCES 0.0.0.0:14001
    at Server.setupListenHandle [as _listen2] (net.js:1313:19)
    at listenInCluster (net.js:1378:12)
    at Server.listen (net.js:1466:7)
    at listenToServer (/mnt/d/Workspace/ui/node_modules/@storybook/core/dist/server/build-dev.js:172:20)
    at buildDevStandalone (/mnt/d/Workspace/ui/node_modules/@storybook/core/dist/server/build-dev.js:293:29)
    at process._tickCallback (internal/process/next_tick.js:68:7)

如果我运行python -m http.server 9001,我会得到这个:

Traceback (most recent call last):
  File "C:\Users\default\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\default\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\default\AppData\Local\Programs\Python\Python36\lib\http\server.py", line 1211, in <module>
    test(HandlerClass=handler_class, port=args.port, bind=args.bind)
  File "C:\Users\default\AppData\Local\Programs\Python\Python36\lib\http\server.py", line 1185, in test
    with ServerClass(server_address, HandlerClass) as httpd:
  File "C:\Users\default\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 453, in __init__
    self.server_bind()
  File "C:\Users\default\AppData\Local\Programs\Python\Python36\lib\http\server.py", line 136, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "C:\Users\default\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 467, in server_bind
    self.socket.bind(self.server_address)
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

有没有什么办法可以摆脱这种糟糕的局面?

相关内容