Fix(curl): Prevent hang on successful empty response #1012
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.