Skip to content

Unclosed client session #570

@wanyang6-tal

Description

@wanyang6-tal

Describe the bug

When I use FastAPI for forwarding and set stream=True, for example: async for res in await openai.ChatCompletion.acreate(**kwargs), when this request is terminated before it completes, an exception occurs as follows: [asyncio] [ERROR]: Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x7f0ca458c490>.

To Reproduce

1. Write a FastAPI request using the acreate method to return data in streaming format.
2. Use a packet sending tool to make a request to the written API, terminate the request while receiving data.
3. Wait for a moment, and the exception will be displayed in the terminal.

Code snippets

No response

OS

Linux

Python version

Python 3.11.4

Library version

openai 0.27.8

### Tasks

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed in v1Issues addressed by the v1 beta

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions