Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INSPECTOR worker may handle HTTP request unexpectly when Sanic.start_method="fork" and INSPECTOR=True #2897

Open
1 task done
LCBHSStudent opened this issue Jan 10, 2024 · 0 comments
Labels

Comments

@LCBHSStudent
Copy link

LCBHSStudent commented Jan 10, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When I set Sanic's start_method to fork and enable INSPECTOR, the HTTP requests I send may unexpectedly be processed by the INSPECTOR worker process.

Could this be because the webserver socket inherited from the parent process is not closed when forking the child process?

If there are any suggestions, or if this behavior is expected, please let me know. Thank you to all the excellent library developers.

Code snippet

test server code:

from sanic import Sanic, Request, HTTPResponse, json
import os

Sanic.start_method = "fork"

app = Sanic("test-fork-with-inspector", inspector=True)

@app.get("/test")
async def test_handler(_: Request) -> HTTPResponse:
    return json(body={"pid": os.getpid()})

running server and sending HTTP request:

python -m sanic test_fork_with_inspector:app --worker=1 --host=127.0.0.1 --port=8080

curl -X GET http://localhost:8080/test
{"pid":1199437}  # inspector worker

curl -X GET http://localhost:8080/test
{"pid":1199435}  # nomal worker

Socket fd of inspector worker:

lsof -p 1199437 | grep LISTEN
python  1199437 user   12u     IPv4           24318245      0t0      TCP localhost:http-alt (LISTEN)
python  1199437 user   15u     IPv4           24311762      0t0      TCP localhost:6457 (LISTEN)

Socket fd of normal worker:

lsof -p 1199435 | grep LISTEN
python  1199435 tusen   12u     IPv4           24318245      0t0      TCP localhost:http-alt (LISTEN)

Expected Behavior

inspector worker should not handle regular HTTP requests

How do you run Sanic?

Sanic CLI Python3.8.10

Operating System

Ubuntu 20.04

Sanic Version

Sanic 23.12.0; Routing 23.12.0

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant