mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
This PR fixes a bug that results in a hang in the oauth login flow if a user logs in, then logs out, then logs in again without first closing the browser window. Root cause of problem: We use a local web server for the oauth flow, and it's implemented using the `tiny_http` rust crate. During the first login, a socket is created between the browser and the server. The `tiny_http` library creates worker threads that persist for as long as this socket remains open. Currently, there's no way to close the connection on the server side — the library provides no API to do this. The library also filters all "Connect: close" headers, which makes it difficult to tell the client browser to close the connection. On the second login attempt, the browser uses the existing connection rather than creating a new one. Since that connection is associated with a server instance that no longer exists, it is effectively ignored. I considered switching from `tiny_http` to a different web server library, but that would have been a big change with significant regression risk. This PR includes a more surgical fix that works around the limitation of `tiny_http` and sends a "Connect: close" header on the last "success" page of the oauth flow.