Waiting for API to be ready fails intermittently
See original GitHub issueDescribe the bug
Sometimes when starting up swa
, it hangs on waiting for the API to be available until it times out and exits. Other times it starts up fine. I’ve been seeing this intermittently for a while and I believe I’ve tracked it down to validateDevServerConfig.
That validation uses two different techniques – for the first check, it just opens a raw TCP socket. If that fails, it falls back to the wait-on
library which sends an actual HTTP GET request and validates the response. Since my API function returns a 400 error code for GET /
with no parameters, wait-on
in the current configuration always fails the check. So I think what is happening is swa
succeeds when my API happens to spin up first and only the raw socket check happens, and fails when swa happens to win the race and the wait-on
checks happen.
To Reproduce
- Create an API function that returns 400 error code on a bare
GET /
request. swa start
- Depending on if the API starts accepting connections before swa tries to the connect the first time, it’ll either succeed or hang forever waiting until it times out and exits.
Expected behavior
swa
shouldn’t fail the check if my API function is handling requests but returning an HTTP error response. Ideally also the behavior should be consistent whichever process wins the race.
Screenshots
Desktop (please complete the following information):
- OS: MacOS Big Sur 11.5.2 (20G95)
- Browser [e.g. chrome, safari]: N/A
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (10 by maintainers)
Top GitHub Comments
Sure, I just sent over https://github.com/Azure/static-web-apps-cli/pull/281
Excellent! Then maybe one of the fixes would that we update the resources property, and use
tcp:
instead (in addition?) ofhttp:
. But this would need some manual testing to make sure we don’t break the current behavior.https://github.com/Azure/static-web-apps-cli/blob/e6cbf081971b3f9418e197c7d63f9d5aac3ac194/src/core/utils/net.ts#L57-L59
cc @tkamesh @sgollapudi77 @anthonychu