qqilihq
qqilihq

Reputation: 11454

mongodump waits forever on invalid URL or unreachable server

As part of an automated backup mechanism, we’re running mongodump on a schedule:

mongodump --uri mongodb://mongodb --gzip --archive=/tmp/mongodb_201811161628.gz

Problem: In case either (a) the given URI is invalid, or (b) the server for the given URI is down, mongodump just seems to hang forever, which makes it difficult to propagate any error messages.

Is there any reason, that mongodump obviously has no integrated timeout? Can this be configured optionally? Or will I really have to rely on external tools to handle timeouts?

Upvotes: 3

Views: 301

Answers (1)

qqilihq
qqilihq

Reputation: 11454

We have “solved” this using the timeout utility. Not a really clean solution, because this will blindly terminate mongodump after reaching the specified timeout, no matter if there’s anything happening or not.

This especially means, that potentially long-running dumps will be killed as well, so it’s important to specify a relatively high timeout and to do proper error handling in case of termination by timeout.

timeout --kill-after=5s $OUR_TIMEOUT_VALUE \
   mongodump --uri mongodb://mongodb --gzip --archive=/tmp/mongodb_201811161628.gz

--kill-after is necessary, because mongodump would not terminate on the inital TERM signal.

Upvotes: 1

Related Questions