newrelic-python-agent icon indicating copy to clipboard operation
newrelic-python-agent copied to clipboard

Fast API Websocket coroutines throw attribute error when run with newrelic admin

Open sankarpa opened this issue 2 years ago • 5 comments

Description I am using newrelic agent 8.5.0 with my fastapi which houses both rest and websocket apis. The app get deployed in kubernetes and here is how the container command looks like

   containers:
        - name: a-service
          image: 'a-service:latest'
          command:
            - newrelic-admin
            - run-program
            - uvicorn
            - app.main:app
            - --port=8000
            - --host=0.0.0.0
          resources:
            requests:
              memory: "512Mi"
              cpu: "500m"
            limits:
              memory: "512Mi"
              cpu: "500m"
          ports:
            - containerPort: 8000
              protocol: TCP

The container comes up healthy and runs , but the coroutines throws error with attribute not found error when calling async functions. The same is working fine when i run the container without newrelic-admin

sankarpa avatar Jan 17 '23 15:01 sankarpa

Hello,

Could you perhaps supply a reproduction or at least some more specifics?

I was unable to reproduce any issue with the latest version of the agent. FastAPI has a minimalist example that I ran some testing against. I was using an async websocket endpoint and both sync and async HTTP routes were working alongside it with no issues.

TimPansino avatar Jan 20 '23 00:01 TimPansino

Hello @sankarpa, without reproduction steps we will close this ticket in 30 days.

Ak-x avatar Mar 17 '23 17:03 Ak-x

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 22 '23 04:05 stale[bot]

Hi @Ak-x @TimPansino Sorry for responding late, I am using aioredis pubsub in the websocket functions and the code looks like below.

pubsub = redis.pubsub()       
await pubsub.subscribe(f"{channel_id}")
await websocket.accept()

if I don't use newrelic agent , the subscribe function call works fine .

I get below error if I initialise the newrelic agent and connect to the websocket

AttributeError: 'coroutine' object has no attribute 'subscribe'

sankarpa avatar Jun 14 '23 19:06 sankarpa

@TimPansino Any updates on this?

sankarpa avatar Jun 26 '23 14:06 sankarpa

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 26 '25 12:04 stale[bot]

https://new-relic.atlassian.net/browse/NR-407828

Thanks for the response @sankarpa , we will review in our upcoming iteration

Ak-x avatar Jul 30 '25 12:07 Ak-x

We believe this is a crash due to the agent not supporting aioredis any longer. Upgrading to the latest version of redis.asyncio may resolve this. Our team will investigate our own documentation.

cc: @TimPansino

Ak-x avatar Aug 04 '25 16:08 Ak-x

Closing until we receive additional insight from the community on testing the above.

Ak-x avatar Sep 02 '25 15:09 Ak-x