Skip to content

Commit 99a2899

Browse files
authored
[python] support VERCEL_IPC_PATH along VERCEL_IPC_FD (#12800)
To communicate between our runtime and language runtimes, we use a Unix Domain Socket for ICP. We currently open a Unix Domain Socket via a file descriptor `VERCEL_IPC_FD`, but not all runtimes that we want to support (e.g. Bun & Deno) support that. To easily support any language runtime, we're moving to `VERCEL_IPC_PATH` to let the runtime directly connect to the given IPC socket, instead of opening it via a FD. We need to support both ways right now: - merge this PR that still supports the old way - enable the new `VERCEL_IPC_PATH` behavior in our runtime - delete the old `VERCEL_IPC_FD` in the Python runtime
1 parent c11c355 commit 99a2899

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

.changeset/thin-flowers-own.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vercel/python': patch
3+
---
4+
5+
Support VERCEL_IPC_PATH along with VERCEL_IPC_FD

packages/python/vc_init.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def format_headers(headers, decode=False):
2727
keyToList[key].append(value)
2828
return keyToList
2929

30-
if 'VERCEL_IPC_FD' in os.environ:
30+
if 'VERCEL_IPC_FD' in os.environ or 'VERCEL_IPC_PATH' in os.environ:
3131
from http.server import ThreadingHTTPServer
3232
import http
3333
import time
@@ -36,10 +36,15 @@ def format_headers(headers, decode=False):
3636
import builtins
3737
import logging
3838

39-
ipc_fd = int(os.getenv("VERCEL_IPC_FD", ""))
40-
sock = socket.socket(fileno=ipc_fd)
4139
start_time = time.time()
4240

41+
if 'VERCEL_IPC_FD' in os.environ:
42+
ipc_fd = int(os.getenv("VERCEL_IPC_FD", ""))
43+
sock = socket.socket(fileno=ipc_fd)
44+
else:
45+
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
46+
sock.connect(os.getenv("VERCEL_IPC_PATH", ""))
47+
4348
send_message = lambda message: sock.sendall((json.dumps(message) + '\0').encode())
4449
storage = contextvars.ContextVar('storage', default=None)
4550

0 commit comments

Comments
 (0)