Hi, hoping somebody can point me in the right direction as I’m starting to pull my hair out a bit.
I’ve been trying to get websockets to work in localstack and seem to be having some odd issues around the routes I have defined.
At the moment I am just trying to get $connect, $disconnect and $default to run but it seems consistently the only event I receive is the $connect one. I was initially routing all events to the same lambda and there it got even stranger as the $default event worked if I disabled the $connect route. However, with $connect enabled I no longer get the $default events.
I’ve tried splitting it into sperate lambdas for each route and got largely the same result, only the lambda attached to $connect will ever fire. I’ve even tried the ws example here: https://github.com/localstack/localstack-terraform-samples/tree/master/apigatewayv2-ws-sample and the same thing happens. I see the logs for the auth lambda and the connect lambda but disconnect never seems to fire,
When I look in my logs for the localstack container I can see this error when I test using wscat but I’m not sure what it relates to:
2023-08-22 15:45:51 2023-08-22T14:45:51.892 INFO --- [ asgi_gw_3] localstack.request.http : POST /_localstack_lambda/0c7d26ac4ad295304d98c313d5ea5799/invocations/fb2a586c-1336-491c-8eae-11491cd64519/response => 202
2023-08-22 15:45:51 2023-08-22T14:45:51.900 INFO --- [uncthread227] l.s.apigateway.authorizers : Received authorizer result: {"principalId":"me","policyDocument":{"Version":"2012-10-17","Statement":[{"Action":"execute-api:Invoke","Effect":"Allow","Resource":"arn:aws:execute-api:us-east-1:000000000000:024261e4/beta/$connect"}]},"context":{"stringKey":"stringval","numberKey":123,"booleanKey":true}}
2023-08-22 15:45:51 2023-08-22T14:45:51.924 INFO --- [ asgi_gw_2] localstack.request.http : POST /_localstack_lambda/732cf237e648e611231adaec677aef2b/invocations/c42f9fe6-6e24-4e46-8dc6-71905cefee05/logs => 202
2023-08-22 15:45:51 2023-08-22T14:45:51.928 INFO --- [ asgi_gw_0] localstack.request.http : POST /_localstack_lambda/732cf237e648e611231adaec677aef2b/invocations/c42f9fe6-6e24-4e46-8dc6-71905cefee05/response => 202
2023-08-22 15:45:51 2023-08-22T14:45:51.933 INFO --- [uncthread227] localstack.utils.threads : Thread run method <function AdaptiveThreadPool.submit.<locals>._run at 0xffff60f82200>(None) failed: Traceback (most recent call last):
2023-08-22 15:45:51 File "/opt/code/localstack/.venv/lib/python3.10/site-packages/localstack/utils/threads.py", line 58, in run
2023-08-22 15:45:51 result = self.func(self.params, **kwargs)
2023-08-22 15:45:51 File "/opt/code/localstack/.venv/lib/python3.10/site-packages/localstack/utils/asyncio.py", line 30, in _run
2023-08-22 15:45:51 return fn(*args, **kwargs)
2023-08-22 15:45:51 File "/opt/code/localstack/.venv/lib/python3.10/site-packages/localstack_ext/services/apigateway/integrations.py.enc", line 99, in A
2023-08-22 15:45:51 with RequestContextManager(R):B=v2_invoke_action_from_websocket(A,D,E)
2023-08-22 15:45:51 File "/opt/code/localstack/.venv/lib/python3.10/site-packages/localstack_ext/services/apigateway/integrations.py.enc", line 142, in v2_invoke_action_from_websocket
2023-08-22 15:45:51 C=IntegrationResponse.from_response(C);S=get_event_request_context(B);C=ws_integration_response(A,H,D,C,S);return C
2023-08-22 15:45:51 File "/opt/code/localstack/.venv/lib/python3.10/site-packages/localstack_ext/services/apigateway/integrations.py.enc", line 177, in ws_integration_response
2023-08-22 15:45:51 B=response;C=integr_details.get(_M);A=next(filter(lambda ir:ir.get(_M)==C,api_details.integration_responses.values()))
2023-08-22 15:45:51 StopIteration
2023-08-22 15:45:51
2023-08-22 15:45:51 2023-08-22T14:45:51.933 ERROR --- [functhread46] asyncio : Exception in callback _chain_future.<locals>._set_state(<Future pendi...ask_wakeup()]>, <Future at 0x...StopIteration>) at /usr/local/lib/python3.10/asyncio/futures.py:379
2023-08-22 15:45:51 handle: <Handle _chain_future.<locals>._set_state(<Future pendi...ask_wakeup()]>, <Future at 0x...StopIteration>) at /usr/local/lib/python3.10/asyncio/futures.py:379>
2023-08-22 15:45:51 Traceback (most recent call last):
2023-08-22 15:45:51 File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
2023-08-22 15:45:51 self._context.run(self._callback, *self._args)
2023-08-22 15:45:51 File "/usr/local/lib/python3.10/asyncio/futures.py", line 381, in _set_state
2023-08-22 15:45:51 _copy_future_state(other, future)
2023-08-22 15:45:51 File "/usr/local/lib/python3.10/asyncio/futures.py", line 357, in _copy_future_state
2023-08-22 15:45:51 dest.set_exception(_convert_future_exc(exception))
2023-08-22 15:45:51 TypeError: StopIteration interacts badly with generators and cannot be raised into a Future```
Any help would be greatly appreciated, thanks!