Skip to content
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

Fix infinite loop when the typescript client requests a non-existing table #1876

Closed
KyleAMathews opened this issue Oct 21, 2024 · 5 comments · Fixed by #1880
Closed

Fix infinite loop when the typescript client requests a non-existing table #1876

KyleAMathews opened this issue Oct 21, 2024 · 5 comments · Fixed by #1880
Assignees
Labels

Comments

@KyleAMathews
Copy link
Contributor

The server returns a 400 and this line then restarts the fetching

if (e.status == 400) {

It seems 404 is the proper response code for the server and would fix this issue.

@msfstef msfstef self-assigned this Oct 21, 2024
@thruflo
Copy link
Contributor

thruflo commented Oct 21, 2024

Are there any other cases where a 400 could be returned. Do we also want to fix infinite loop for 400 generally?

@KyleAMathews
Copy link
Contributor Author

I'm not sure why we special-case the 400 there — 409 is the code we use to tell the client to refetch. In general 4xx codes are a user error so the client should just throw ann error and quit.

But yeah, to your point, we need to do two things — return 404 from the server for non-existing tables and don't special case the 400 status code.

@balegas
Copy link
Contributor

balegas commented Oct 21, 2024

We used a 400 initially on the server to not specialize the reasons. I guess things have evolved.

@balegas
Copy link
Contributor

balegas commented Oct 21, 2024

One related problem is that the constructor makes the first fetch call, so non-actionable errors can't be caught. We should change the client to separate resource creation (i.e. constructor) from connection initialisation (start) to make it easier to catch non-actionable errors.

@msfstef
Copy link
Contributor

msfstef commented Oct 22, 2024

We should change the client to separate resource creation (i.e. constructor) from connection initialisation (start) to make it easier to catch non-actionable errors.

I agree, I think we should open a new issue about this in particular.

I've opened #1880 that should fix this immediate issue of infinite loops.

As an aside, I don't think we should be returning 404 errors since as far as we're concerned any request that defines a shape that is not valid (inexistent or invalid root table, inexistent or invalid column names, mismatched shape id and definition) are badly formed requests, and thus 400s.

If we want to split out errors (e.g. missing table from PG is 404, invalid table name is 400), it would be perhaps more explicit and informative but the handling from our side would be exactly the same, so it would just be a matter of improving API semantics.

msfstef added a commit that referenced this issue Oct 23, 2024
Fixes #1876

The issue was that we were sending `must-refetch` messages with some of
our 400s, although they were unrecoverable and re-fetching would trigger
an infinite loop.

I've made the server send 400 errors for the cases where the `shape_id`
and `shape_definition` do not match, with an explanatory message, and
I've made the client terminate when receiving such an error.

As a temporary measure, the error is not thrown into the ether but
stored in the `ShapeStream` (accessible via `stream.error`).

We have had some discussions with @balegas about making errors more
"handleable" by changing our approach to the `ShapeStream`
instantiation. I think this warrants opening a new issue and
corresponding PR to discuss more thoroughly.
KyleAMathews pushed a commit that referenced this issue Nov 1, 2024
Fixes #1876

The issue was that we were sending `must-refetch` messages with some of
our 400s, although they were unrecoverable and re-fetching would trigger
an infinite loop.

I've made the server send 400 errors for the cases where the `shape_id`
and `shape_definition` do not match, with an explanatory message, and
I've made the client terminate when receiving such an error.

As a temporary measure, the error is not thrown into the ether but
stored in the `ShapeStream` (accessible via `stream.error`).

We have had some discussions with @balegas about making errors more
"handleable" by changing our approach to the `ShapeStream`
instantiation. I think this warrants opening a new issue and
corresponding PR to discuss more thoroughly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants