-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(client): add timeout to fetchResource
to prevent hangs
#2322
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this!
|
||
"github.com/Jigsaw-Code/outline-apps/client/go/outline/platerrors" | ||
) | ||
|
||
const fetchTimeout = 10 * time.Second |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally the TS code would specify this, but this is a good mitigation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, TS code should combine fetchResource
and the next establishVPN
into a single "transaction", so both operations can be cancelled by a single context
object (for example, when a user wants to connect to another server, we should cancel all existing fetchResource
and establishVPN
operations).
@@ -100,3 +101,29 @@ func TestFetchResource_BodyReadError(t *testing.T) { | |||
require.Equal(t, platerrors.FetchConfigFailed, perr.Code) | |||
require.Error(t, perr.Cause) | |||
} | |||
|
|||
func TestFetchResource_Timeout(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice test!
This PR adds a timeout to the
fetchResource
function. Previously,fetchResource
could hang indefinitely if the requested resource was unavailable or extremely slow to respond. (You can use this key to test: https://httpstat.us/204?sleep=120000#Timeout)Problems without the timeout
UV_THREADPOOL_SIZE
). This restricts the number of concurrent native API (N-API) calls, (for example,fetchResource
). If more than fourfetchResource
calls were blocked indefinitely, it would exhaust the thread pool, preventing other N-API calls from executing. Notably, this blocked thecloseVPN
call triggered by the "Quit" action, making users unable to quit the application.http.Get
call withinfetchResource
would consume system resources unnecessarily, potentially leading to performance degradation or even instability in extreme cases.Note
This solution is more like a mitigation, not a complete fix, for the NodeJS thread pool limitation.
Further improvements might involve implementing a more sophisticated queuing mechanism or increasing the thread pool size (if feasible).