Skip to content

Conversation

@drzraf
Copy link
Collaborator

@drzraf drzraf commented Sep 11, 2021

A couple of fixes regarding abort() (observed in the particular case of a stream didn't compute adequately the number of chunks)

(Note: An better codepath is still to be found to replace the current workaround used in readStreamChunk)

@drzraf drzraf changed the title Flowchunk xhr abort fixes FlowChunk: xhr abort fixes Sep 11, 2021
@drzraf drzraf requested a review from AidasK September 11, 2021 20:41
@drzraf drzraf added the v3 label Sep 11, 2021
if (this.xhr) {
this.xhr.abort();
}
this.xhr = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember this was made on purpose to prevent some kind of loop happening. I think abort throws some kind of synchronous event and that event calls abort there abort is called once again and it throws an error that it was already aborted or something.

Copy link
Collaborator Author

@drzraf drzraf Sep 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could happen if something registered the abort event of the XHR itself:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/abort_event
But none of the code does this AFAICT. I'd say it's up to the consumer to attach "safe" event handler to XHR abort.
Don't you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it solves your problem and we don't have any other explanation, let's leave it in a way it works best for you

src/FlowChunk.js Outdated
// on this FlowFile.
this.pendingRetry = false;
this.xhr = {readyState: 5, status: 1 };
this.xhr = {readyState: 5, status: 200, abort: e => null };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how I missed this, but creating fake objects doesn't seem right. Other approach should be considered

Copy link
Collaborator Author

@drzraf drzraf Sep 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. What do you suggest? Here we get a chunk and we identify, lately, that it's useless and we want to discard it without tainting the chunk/file status. (It's been completed)

Copy link
Collaborator Author

@drzraf drzraf Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative fake XHR:

this.xhr = new XMLHttpRequest();
this.xhr.open("GET", "data:");
this.xhr.send();

A possible issue with this exists if a CSP is set but connect-src omits data:. (XHR would fail).

Do you see another safe solution?
As per status(), the two conditions (regarding the XHR) are clear: this.xhr.readyState must exist and be equal to 4 and this.xhr.status must be an accepted status.

Copy link
Member

@AidasK AidasK Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just think we can rewrite this code part not to use fake xhr, because it might be used by other developers. It might raise some unexpected issues because it should be an instance of XMLHttpRequest but sometimes it's just an object. Just like in strongly typed languages, variable type should not change as it prevents some bugs.

Using this.xhr.open("GET", "data:"); does not seem right either, just a waste of resources and adds some complexity. Why do we have to have it defined? setting it to null or using other variable should work fine too imo.

Copy link
Collaborator Author

@drzraf drzraf Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree with you concern, but

  • By rewrite, do you mean rewrite FlowChunk::status() ? How?
  • Can we plan such a (probably deeper change) for a subsequent PR and keep this one focused on fixing abort()? as that would allow me to move forward.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can merge as this is not really an issue of this MR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How? Not sure, but it smells a bit in the current state

@AidasK
Copy link
Member

AidasK commented Sep 13, 2021

Approved

@drzraf drzraf merged commit caf4964 into flowjs:v3 Sep 13, 2021
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 this pull request may close these issues.

2 participants