Comments (6)
Mind adding the exact options you're using and the version of consul
and node-consul
.
from node-consul.
Here's an example of what I'm sending:
{
key: `my-key`,
value: `my-leader-value`,
session: {
lockdelay: '1s',
checks: ['serfHealth'],
name: 'leader-election',
ttl: '10s'
}
}
from node-consul.
I think I might be running into this same problem. I wrote this handy little class:
class Distributed {
...
electLeader(key) {
const lock = this.consulClient.lock({
key: `${this.deployKey}/leader/${key}`,
session: {
name: `${this.deployKey}-${key}`,
ttl: "15s"
},
});
lock.acquire();
return lock;
}
withLock(key, fn) {
const deferred = promiseTools.defer();
let done = false;
const lock = this.electLeader(key);
lock.on('acquire', () => {
if (done) {return;}
done = true;
return Promise.resolve()
.then(fn)
.then(
result => {
lock.release();
deferred.resolve(result);
},
err => {
lock.release();
deferred.reject(err);
}
);
});
lock.on('err', err => {
if (done) {return;}
done = true;
log.error({err: err}, "Error acquiring upgrade lock");
deferred.error(err);
});
return deferred.promise;
};
}
So I can do distributed.withLock(() => /* do stuff here */)
. And today I discovered in my logs:
ERROR: ./l/app: Potentially Unhandled Rejection at: Promise [object Promise]
err: Error: no lock in use
at create (./node_modules/consul/lib/errors.js:14:5)
at Object.validation (./node_modules/consul/lib/errors.js:26:15)
at Lock.release (./node_modules/consul/lib/lock.js:110:32)
Which sounds a bit terrifying. :P I'm on node-consul 0.28.0, and consul 0.7.2.
from node-consul.
Hmm... I tried running my "withLock()" with a 15 minute delay in the middle, and it worked correctly. Maybe I'm just doing too much stuff and starving out sending the session update. I'll try again with a longer-than-15s session timeout.
from node-consul.
Ok, with some console.logging, I've discovered a little more about what's going on:
Apr 19 16:51:57 [89211] INFO: ./l/s/u/Upgrader: Waiting for upgrade lock...
...
**** lock.monitor error { Error: consul: kv.get: request timed out (16000ms)
at create (/Users/jwalton/benbria/loop-common/node_modules/papi/lib/errors.js:14:5)
at Object.timeout (/Users/jwalton/benbria/loop-common/node_modules/papi/lib/errors.js:62:15)
at ClientRequest.<anonymous> (/Users/jwalton/benbria/loop-common/node_modules/papi/lib/client.js:532:20)
at emitNone (events.js:86:13)
at ClientRequest.emit (events.js:185:7)
at Timeout.<anonymous> (/Users/jwalton/benbria/loop-common/node_modules/papi/lib/client.js:520:11)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
isPapi: true, isTimeout: true }
**** lock.monitor error { Error: consul: kv.get: request aborted
at create (/Users/jwalton/benbria/loop-common/node_modules/papi/lib/errors.js:14:5)
at Object.abort (/Users/jwalton/benbria/loop-common/node_modules/papi/lib/errors.js:50:15)
at Watch.abort (/Users/jwalton/benbria/loop-common/node_modules/papi/lib/client.js:511:32)
at Watch.g (events.js:291:16)
at emitNone (events.js:86:13)
at Watch.emit (events.js:185:7)
at Watch.end (/Users/jwalton/benbria/loop-common/node_modules/consul/lib/watch.js:84:8)
at /Users/jwalton/benbria/loop-common/node_modules/consul/lib/lock.js:315:17
at Timeout._onTimeout (/Users/jwalton/benbria/loop-common/node_modules/consul/lib/utils.js:198:33)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
isPapi: true, isAbort: true }
**** lock.monitor end
**** Lock._end() err=undefined
Apr 19 16:52:16 [89211] ERROR: /U/j/b/l/l/distributed: End for held lock!
So the monitor
created by the Lock is timing out, and as a result my lock emits an "end" with no "error" out from under me.
from node-consul.
@jwalton Yeah, the lock error
event is for error reporting and not really useful for tracking the status of the lock. You want to listen to lock.on('end')
and immediately assume the lock is lost/released when that's emitted.
It would be useful to look at the consul logs for the agent when the timeout occurred, it might shed some light into why the timeout is happening.
Also, FYI, you can get really detailed logs from the consul http client by listening on log
.
Example:
var consul = require('consul')();
consul.on('log', console.log);
from node-consul.
Related Issues (20)
- access to keys response HOT 3
- TypeError: consul_1.default is not a constructor HOT 1
- TypeScript Support for consul.query HOT 1
- There is no accessible history.md or changelog.md file HOT 1
- Consul queries providing `tag` are deprecated HOT 2
- Long Polling index should be verified > 0 after initial response
- Reset index of watch job if index ever decreases HOT 1
- Can't invoke "new Consul()" HOT 1
- Can't invoke "new Consul()" constructor in typescript app HOT 1
- Release docs? HOT 4
- Typescript support for client.watch HOT 1
- Typescript suppor for grpc healthcheck's HOT 1
- Add Typescript support HOT 2
- Grype scanner found all this vulnerabilities in the library CVE-2018-25046, CVE-2020-13250, CVE-2021-38698, CVE-2022-40716, CVE-2020-7219, CVE-2020-28053, CVE-2021-3121, CVE-2021-37219 HOT 1
- support for kv.List HOT 2
- extend host:port to support multiple agents HOT 4
- Don't set x-consul-token if it's undefined
- how to watch service? HOT 1
- Grpc Check register request ignores `tls_skip_verify` HOT 4
- Question about the usage of "end" function in watch.js HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-consul.