[Errno 57] Socket is not connected

Hi, I am developing a simple app with Sanic, I have been using older version, but moved to 22.12 recently. Running on my localhost, every time I stop the process with Keyboard interrupt, it raises an error:

Sanic.serve(primary=app, app_loader=loader)
  File ".../lib/python3.8/site-packages/sanic/mixins/startup.py", line 880, in serve
OSError: [Errno 57] Socket is not connected

It then doesn’t execute the rest of the ‘shutdown’ code and so other my stuff don’t get executed…
But while running, it responds and runs normally.

This is how I run the server:

if __name__ == "__main__":
  loader = AppLoader(factory=partial(create_api_app))
  app = loader.load()
  app.prepare(port=port, debug=debug, access_log=debug)
  Sanic.serve(primary=app, app_loader=loader)

and from CLI simply:

python main.py

My development machine is iMac with MacOS 13.2.1
Am I doing something wrong here?

This is MacOS specific. I was able to duplicate on MacOS 13.2.1 - looks like the SIGINT isn’t being cleanly handled for some reason.

The same code works fine on Linux. Can you please raise an issue for this?

This is known. You can ignore it as harmless. I either already merged a fix or have a branch waiting and it will be part of 23.3 release. Thanks for bringing this up though :sunglasses:

Thanks for your quick answers (on Saturday :sweat_smile: ), but let me give a related question then. The main reason why I bothered is, because I am using the great feature of running custom process via WorkManager Worker Manager | Sanic Framework and exactly as in the example having try…except block with KeyboardInterrupt, where I do some tidying up. But the code never gets called. You think this could be related to this issue (it seems to me, it is…) or should I be looking for some other workaround or solution to correctly do the clean up…
Thanks once again!