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

[ts] Timeout when loading fgb files using takeAsync+deserialize starting with v3.27.3 #358

Open
twelch opened this issue Apr 8, 2024 · 3 comments

Comments

@twelch
Copy link

twelch commented Apr 8, 2024

When using flatgeobuf Javascript package version 3.27.3 and higher in a node v20.12.1 environment, I do not receive a response when loading a flatgeobuf from an external URL using deserialize + takeAsync.

I can't tell exactly what is happening, it's not throwing an error for me, but I have reproduced the issue - https://github.com/twelch/flatgeobuf-error-demo/tree/main. see README for steps, the test (which is based on this internal fgb test) will timeout as-is and after downgrading to 3.27.2 it will pass.

This seems to only occur when I am using the published library, adding this test to the internal flatgeobuf suite and it will pass/load just fine.
This seems to occur with any flatgeobuf loaded using this method, at least all of mine, not just this one published fgb, which is a simple polygon boundary for the world.

{
    "type": "FeatureCollection",
    "features": [
      {
        "type": "Feature",
        "properties": {
          "name": "World boundary",
          "description": "World"
        },
        "geometry": {
          "coordinates": [
            [
              [
                -180,
                90
              ],
              [
                -180,
                -90
              ],
              [
                180,
                -90
              ],
              [
                180,
                90
              ],
              [
                -180,
                90
              ]
            ]
          ],
          "type": "Polygon"
        }
      }
    ]
  }
@bjornharrtell
Copy link
Member

Thanks for the report and nice reproduction. I have noticed something similar and found it it happens only on node native fetch api. The tests in flatgeobuf works because it includes node-fetch polyfill (globally). I have as of yet no clue why it times out with node native fetch which is still marked as experimental.

Because node native fetch is experimental I'm not sure how deep I want to dig at this time. That said, it's a nice find that it worked in 3.27.2, that means it likely has some relation to dependency upgrades done in 987499b and 6c0124c. Main suspect is web-streams-polyfill.

@twelch
Copy link
Author

twelch commented Apr 8, 2024

That's helpful. I can confirm that polyfilling with node-fetch in the test file gets it to pass as you said.

fetch API I understand is now stable in node v21 and I was able to get the test to pass with latest flatgeobuf when using it. It seems to issue will work itself out eventually.

@twelch
Copy link
Author

twelch commented Apr 8, 2024

Additional info on workaround, the polyfill code that node-fetch suggests on their github will not work because it only applies the fill if fetch does not exist. But in node v20 global.fetch does exist, it just doesn't work properly. In my situation I am locked to Node v20 until the next LTS, so it is acceptable to always polyfill so:

if (!globalThis.fetch) {
  globalThis.fetch = fetch
  globalThis.Headers = Headers
  globalThis.Request = Request
  globalThis.Response = Response
}

to become

if (globalThis) {
  globalThis.fetch = fetch
  globalThis.Headers = Headers
  globalThis.Request = Request
  globalThis.Response = Response
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants