Commit b88ba2001642b41d2778587977b9e004956ccf07
1 parent
6e61afe0ff
Exists in
master
Lock on config-sender save
Showing 3 changed files with 16 additions and 2 deletions Side-by-side Diff
lib/apiserver/router-config-senders.js
... | ... | @@ -6,12 +6,20 @@ const express = require('express'); |
6 | 6 | const config = require('komodo-sdk/config'); |
7 | 7 | const logger = require('komodo-sdk/logger'); |
8 | 8 | |
9 | +const locks = require('locks'); | |
10 | +const mutexSave = locks.createMutex(); | |
11 | + | |
9 | 12 | const router = express.Router(); |
10 | 13 | module.exports = router; |
11 | 14 | |
12 | 15 | function saveConfig() { |
13 | - fs.writeFile(global.KOMODO_SDK_CONFIG_FILENAME, JSON.stringify(config, null, 4), (err) => { | |
14 | - logger.warn(`APISERVER: ERROR writing config file. ${err.toString()}`); | |
16 | + mutexSave.lock(() => { | |
17 | + fs.writeFile(global.KOMODO_SDK_CONFIG_FILENAME, JSON.stringify(config, null, 4), (err) => { | |
18 | + if (err) { | |
19 | + logger.warn(`APISERVER: ERROR writing config file. ${err.toString()}`); | |
20 | + } | |
21 | + mutexSave.unlock(); | |
22 | + }); | |
15 | 23 | }); |
16 | 24 | } |
17 | 25 |
package-lock.json
... | ... | @@ -2631,6 +2631,11 @@ |
2631 | 2631 | "path-exists": "^3.0.0" |
2632 | 2632 | } |
2633 | 2633 | }, |
2634 | + "locks": { | |
2635 | + "version": "0.2.2", | |
2636 | + "resolved": "https://registry.npmjs.org/locks/-/locks-0.2.2.tgz", | |
2637 | + "integrity": "sha1-JZkz0TJ8uvD9NmL4//3jaAnYTO0=" | |
2638 | + }, | |
2634 | 2639 | "lodash": { |
2635 | 2640 | "version": "4.17.15", |
2636 | 2641 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", |
package.json
... | ... | @@ -23,6 +23,7 @@ |
23 | 23 | "express": "^4.17.1", |
24 | 24 | "komodo-center-messaging-client-lib": "git+http://gitlab.kodesumber.com/komodo/komodo-center-messaging-client-lib.git", |
25 | 25 | "komodo-sdk": "git+http://gitlab.kodesumber.com/komodo/komodo-sdk.git", |
26 | + "locks": "^0.2.2", | |
26 | 27 | "moment": "^2.24.0", |
27 | 28 | "node-cache": "^4.2.1", |
28 | 29 | "redis": "^2.8.0", |