Skip to content

fix: PGPool error handling and app.js catch/callback bugs - #111

Merged
arnoldcastro5000 merged 1 commit into
Greenstand:masterfrom
arnoldcastro5000:fix/pgpool-error-handling-app-catch-bugs
Jun 30, 2026
Merged

fix: PGPool error handling and app.js catch/callback bugs#111
arnoldcastro5000 merged 1 commit into
Greenstand:masterfrom
arnoldcastro5000:fix/pgpool-error-handling-app-catch-bugs

Conversation

@arnoldcastro5000

@arnoldcastro5000 arnoldcastro5000 commented May 15, 2026

Copy link
Copy Markdown
Collaborator

What

Fixes four confirmed bugs in PGPool.js and app.js that cause
permanent request freezes, memory leaks, unhandled process crashes,
and broken 500 error responses.

Fixes Bug 1 in issue: Greenstand/treetracker-infrastructure#315
Related to issue: Greenstand/treetracker-infrastructure#300

Why

PGPool.js

  • A DB error left isFetching[sql] = true permanently, freezing all
    future requests for that SQL string and leaking queued callbacks
  • The getQuery() Promise never rejected on DB error — callers hung
    indefinitely with no error signal

app.js

  • All 4 route catch blocks referenced undefined error instead of
    caught e, causing a ReferenceError that prevented 500 responses
    from being sent
  • throw err inside non-async map.render() and fromString
    callbacks bypassed the outer try/catch, generating unhandled
    exceptions that crash the Node process

Change

PGPool.js

  • Adopted Node.js error-first callback convention cb(err, result)
    on both success and error paths
  • catch block now resets isFetching[sql] and drains the queue,
    calling each pending callback with the error
  • getQuery() consumer updated to handle (err, result) and
    propagate errors via rej(err)

app.js

  • fromString callback: replaced throw "failed" with return rej(err)
  • Both grid routes: renamed _rejrej to bring rejector into scope
  • All render callbacks: replaced throw err with return rej(err)
  • All 4 catch blocks: fixed errore

Follow-up

  • Tests for new error paths in PGPool.js (fetch failure, queue drain)
    and app.js (rej propagation) to be added in a subsequent PR per
    CONTRIBUTING.md testing requirements.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change
  • Documentation update

@arnoldcastro5000

Copy link
Copy Markdown
Collaborator Author

@dadiorchen for your review.

Fixes Bug 1 in issue: Greenstand/treetracker-infrastructure#315

@arnoldcastro5000

Copy link
Copy Markdown
Collaborator Author

The 2 stuck pods need to be cleared separately. They are not handled by this PR.

PS D:\git\node-mapnik-1> kubectl get pods -n tile-server
NAME READY STATUS RESTARTS AGE
treetracker-tile-server-76c56645c4-7kbfj 1/1 Running 11 (7h3m ago) 22d
treetracker-tile-server-76c56645c4-cn2pt 0/1 ContainerStatusUnknown 6 (39d ago) 41d
treetracker-tile-server-76c56645c4-slzls 1/1 Running 28 (7h3m ago) 36d
treetracker-tile-server-76c56645c4-z8k82 0/1 ContainerStatusUnknown 6 (39d ago) 41d
PS D:\git\node-mapnik-1>

@arnoldcastro5000

Copy link
Copy Markdown
Collaborator Author

Hi @dadiorchen , need your comments before I proceed with testing on the dev environment.

@arnoldcastro5000

Copy link
Copy Markdown
Collaborator Author

hi @dadiorchen , requesting your review.

@arnoldcastro5000

Copy link
Copy Markdown
Collaborator Author

latest status

arnold@kali:~/projects/greenstand$ kubectl get pods -n tile-server
doctl: 2026/06/18 21:27:58 Using cached credential
NAME                                       READY   STATUS    RESTARTS      AGE
treetracker-tile-server-76c56645c4-7mbdx   1/1     Running   5 (10h ago)   5d17h
treetracker-tile-server-76c56645c4-pgpdf   1/1     Running   5 (10h ago)   5d17h
arnold@kali:~/projects/greenstand$

@dadiorchen dadiorchen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is good to me
To Deploy this, please let me know if there is any problem @arnoldcastro5000 because this repo is not a normal application

@arnoldcastro5000
arnoldcastro5000 merged commit 82f54b9 into Greenstand:master Jun 30, 2026
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 4.36.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@arnoldcastro5000

Copy link
Copy Markdown
Collaborator Author

initial run failed due to github hard-failing actions v1. correcting build-deploy.yml

@arnoldcastro5000

Copy link
Copy Markdown
Collaborator Author

workflow run now progressed beyond the build-deploy.yml corrections. error in Dockerfile:

  RUN curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
  W: GPG error: https://deb.nodesource.com/node_14.x bionic InRelease: NO_PUBKEY 1655A0AB68576280
  ERROR: failed to build ... exit code: 1

@arnoldcastro5000

Copy link
Copy Markdown
Collaborator Author

Summary of changes to build-deploy.yml

  1. upload-artifact@v1 → v4 because v1 is auto-failed by GitHub
  2. download-artifact@v1 → v4 + path: added because v1 auto-failed; path: restores the image-tag-${sha}/ folder the downstream cat reads

Summary of changes to Dockerfile

  1. NodeSource setup_14.x → direct nodejs.org tarball because NodeSource Node 14 repo's GPG key is dead; tarball keeps Node 14, no APT repo
  .github/workflows/build-deploy.yml (2 hunks)

  --- a/.github/workflows/build-deploy.yml
  +++ b/.github/workflows/build-deploy.yml
  @@ -61,7 +61,7 @@
       - name: persist tag name
  -      uses: actions/upload-artifact@v1
  +      uses: actions/upload-artifact@v4
         with:
           name: image-tag-${{github.sha}}
           path: image-tag
  @@ -83,9 +83,10 @@
       - name: Download tag name
  -      uses: actions/download-artifact@v1
  +      uses: actions/download-artifact@v4
         with:
           name: image-tag-${{github.sha}}
  +        path: image-tag-${{github.sha}}

  Dockerfile (1 hunk)

  --- a/Dockerfile
  +++ b/Dockerfile
  @@ -7,7 +7,7 @@
   #TODO We should build the tile2 image from node 14 alpine
  -RUN curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
  -RUN sudo apt-get install -y nodejs
  +RUN curl -fsSL https://nodejs.org/dist/v14.21.3/node-v14.21.3-linux-x64.tar.gz \
  +  | sudo tar -xz -C /usr/local --strip-components=1
   RUN make release_base

@arnoldcastro5000
arnoldcastro5000 deleted the fix/pgpool-error-handling-app-catch-bugs branch June 30, 2026 02:53
@arnoldcastro5000

arnoldcastro5000 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

Deployed to prod on June 30, 2026. Deployment logs in slack.

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