Skip to content

Fix(curl): Prevent hang on successful empty response #1012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

La-Loutre
Copy link

Hello, while developing an extension that uses the gptel API, I encountered an intermittent bug where a request callback would occasionally fail to trigger. This left my script hanging, as it never received the final signal for a completed request.

I debugged the issue with the help of an AI, and it identified the root cause within gptel's handling of non-streaming curl requests. Here's a summary of the findings:

A request would hang if the server returned a successful HTTP status (200 OK) but with an empty or malformed JSON body. The internal sentinel function failed to call the final callback because its conditional logic required a non-nil response body on a successful request.

This patch fixes the problem by making the callback trigger dependent only on a completed HTTP status. This change ensures the client is always notified when a request finishes, preventing the silent hang.

A non-streaming request would hang if the server returned a
successful HTTP status (200 OK) but with an empty or malformed
JSON body.

The sentinel function failed to call the final callback because
its conditional logic required a non-nil response body on a
successful request. This change makes the callback trigger
dependent only on a completed HTTP status, ensuring the client is
always notified and preventing the silent hang.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant