Skip to content

Commit da282c2

Browse files
authored
fix "resource has children" error in spin_sdk.http.send (#116)
We were neglecting to drop the resource returned by `incoming-response.headers` prior to dropping the `incoming-response` itself. Either I'm crazy and this never worked or `wasmtime-wasi` wasn't enforcing this parent-child relationship last time I tested it. Either way, this points to an urgent need for CI test coverage. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent dd764ad commit da282c2

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/spin_sdk/http/__init__.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ async def send_async(request: Request) -> Response:
163163
url_parsed = parse.urlparse(request.uri)
164164

165165
match url_parsed.scheme:
166-
case "http":
167-
scheme: Scheme = Scheme_Http()
168-
case "https":
169-
scheme = Scheme_Https()
170-
case "":
171-
scheme = Scheme_Http()
172-
case _:
173-
scheme = Scheme_Other(url_parsed.scheme)
166+
case "http":
167+
scheme: Scheme = Scheme_Http()
168+
case "https":
169+
scheme = Scheme_Https()
170+
case "":
171+
scheme = Scheme_Http()
172+
case _:
173+
scheme = Scheme_Other(url_parsed.scheme)
174174

175175
headers_dict = request.headers
176176

@@ -218,14 +218,16 @@ async def send_async(request: Request) -> Response:
218218
while True:
219219
chunk = await response_body.next()
220220
if chunk is None:
221+
headers = incoming_response.headers()
221222
simple_response = Response(
222223
incoming_response.status(),
223224
dict(map(
224225
lambda pair: (pair[0], str(pair[1], "utf-8")),
225-
incoming_response.headers().entries()
226+
headers.entries()
226227
)),
227228
bytes(body)
228229
)
230+
headers.__exit__(None, None, None)
229231
incoming_response.__exit__(None, None, None)
230232
return simple_response
231233
else:

0 commit comments

Comments
 (0)