Skip to content

Conversation

tkren
Copy link

@tkren tkren commented Mar 24, 2015

Running pgagent on Debian jessie with an SQL jobstep crashes the worker thread with the error message Caught unhandled unknown exception; terminating. Both job and jobstep status then remain as r (running) until the pgagent process quits. After restarting pgagent, which cleans up the job status and sets it to d (aborted), the job containing the SQL jobstep is free to run again, but the next run will end up in the same deadlock situation.

I have tracked down the problem to DBconn::GetLastError(), which gets called after each SQL jobstep execution in Job::Execute(): there, DBconn::GetLastError() throws an exception whenever the last error message is empty.

This pull request fixes this problem by adding missing bounds checks to DBconn::GetLastError().

Here is a log of pgagent with an SQL jobstep:

$ pgagent -l 2 -f hostaddr=127.0.0.1 port=5432 dbname=pgdb user=pgdb  
DEBUG: Creating primary connection
DEBUG: Connection Information:
DEBUG:      user         : pgdb
DEBUG:      port         : 5432
DEBUG:      host         : 127.0.0.1
DEBUG:      dbname       : pgdb
DEBUG:      password     : 
DEBUG:      conn timeout : 0
DEBUG: Connection Information:
DEBUG:      user         : pgdb
DEBUG:      port         : 5432
DEBUG:      host         : 127.0.0.1
DEBUG:      dbname       : pgdb
DEBUG:      password     : 
DEBUG:      conn timeout : 0
DEBUG: Creating DB connection: user=pgdb port=5432 hostaddr=127.0.0.1 dbname=pgdb
DEBUG: Database sanity check
DEBUG: Clearing zombies
DEBUG: Checking for jobs to run
DEBUG: Sleeping...
DEBUG: Clearing inactive connections
DEBUG: Connection stats: total - 1, free - 0, deleted - 0
DEBUG: Checking for jobs to run
DEBUG: Sleeping...
[...]
DEBUG: Clearing inactive connections
DEBUG: Connection stats: total - 1, free - 0, deleted - 0
DEBUG: Checking for jobs to run
DEBUG: Sleeping...
DEBUG: Connection stats: total - 1, free - 0, deleted - 0
DEBUG: Checking for jobs to run
DEBUG: Creating job thread for job 5
DEBUG: Creating DB connection: user=pgdb port=5432 hostaddr=127.0.0.1 dbname=pgdb
DEBUG: Allocating new connection to database pgdb
DEBUG: Starting job: 5
DEBUG: Sleeping...
DEBUG: Creating DB connection: user=pgdb port=5432 hostaddr=127.0.0.1 dbname=pgdb dbname=pgdb
DEBUG: Allocating new connection to database pgdb
DEBUG: Executing SQL step 40 (part of job 5)
*** Caught unhandled unknown exception; terminating
DEBUG: Destroying job thread for job 5
DEBUG: Checking for jobs to run
DEBUG: Sleeping...
DEBUG: Clearing inactive connections
DEBUG: Connection stats: total - 3, free - 0, deleted - 0
DEBUG: Checking for jobs to run
DEBUG: Sleeping...
DEBUG: Clearing inactive connections
DEBUG: Connection stats: total - 3, free - 0, deleted - 0
DEBUG: Checking for jobs to run
DEBUG: Sleeping...
[...]

@tkren tkren closed this Mar 26, 2015
@tkren tkren deleted the sql_jobstep_unhandled_exception branch March 26, 2015 13:06
@repo-lockdown
Copy link

repo-lockdown bot commented Jun 17, 2019

Thanks for your Pull Request! 😄 This repo on GitHub is just a mirror of our real git repositories though, and can't really handle PRs. 😦 Hopefully you can redo the PR, and direct it to the git.postgresql.org repos? We have a developer guide, if that helps: https://wiki.postgresql.org/wiki/So,_you_want_to_be_a_developer%3F. If this was a PR for pgAdmin, please visit https://www.pgadmin.org/docs/pgadmin4/dev/submitting_patches.html.

@repo-lockdown repo-lockdown bot locked and limited conversation to collaborators Jun 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant