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

Timeout on fetch while loading 841 pmtiles sources – Proposed fix by adjusting undici dispatcher #1468

Open
marcioecom opened this issue Feb 23, 2025 · 0 comments

Comments

@marcioecom
Copy link

When using a configuration file (config.json) containing 841 pmtiles sources, tileserver-gl (v5.1.3) encounters a timeout error when fetching the sources. Initially, the log only displayed "fetch failed", but after adding a console.log(err) at line 768 in src/server.js, I obtained more detailed error information:

Using specified config file from config.json
Starting server
Listening at http://[::]:8080/
TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11730:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at runNextTicks (node:internal/process/task_queues:64:3)
    at process.processImmediate (node:internal/timers:449:9) {
  cause: ConnectTimeoutError: Connect Timeout Error
      at onConnectTimeout (node:internal/deps/undici/undici:6869:28)
      at node:internal/deps/undici/undici:6825:50
      at Immediate._onImmediate (node:internal/deps/undici/undici:6857:13)
      at process.processImmediate (node:internal/timers:478:21) {
    code: 'UND_ERR_CONNECT_TIMEOUT'
  }
}
fetch failed

Steps to Reproduce:

  1. Create a config.json file containing 841 pmtiles sources.
{
  "options": {},
  "data": {
    "sampleSource1": {
      "pmtiles": "https://example.com/tiles/sample1.pmtiles"
    },
    "sampleSource2": {
      "pmtiles": "https://example.com/tiles/sample2.pmtiles"
    }
    // ... additional sources
  }
}
  1. Start tileserver-gl using the following Docker command:
    docker run --name tileserver -v $(pwd)/config.json:/data/config.json --restart unless-stopped -p 8080:8080 -d maptiler/tileserver-gl
  2. Check the logs and observe the timeout error as described.

Environment:

  • Tileserver-gl: Version 5.1.3
  • Platform: Docker (using the maptiler/tileserver-gl image)
  • Configuration: config.json with 841 pmtiles sources (attachment available if needed)

Reference:

Proposed Solution:
I tested a solution suggested in the undici issue, which involves setting a custom global dispatcher for undici by increasing the number of connections in the pool. The code used was:

import { Agent, Pool, setGlobalDispatcher } from 'undici';

setGlobalDispatcher(
  new Agent({
    factory: (origin) => new Pool(origin, { connections: 128 }),
  }),
);

With this modification, the server is able to load all the sources (even when using a pool with just 1 connection, albeit with reduced performance). This approach can be considered either a temporary workaround or the starting point for making this configuration customizable via environment variables or configuration parameters.

Final Considerations:
I would like to discuss if this change is appropriate for the project and, if so, I can open a pull request with the implementation and necessary documentation updates. I believe this change will help handle scenarios where a large number of sources are loaded simultaneously.

Thank you for your attention, and I'm available for any further questions or adjustments.


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

No branches or pull requests

1 participant