Skip to content

Commit

Permalink
v1.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-person committed Sep 8, 2022
1 parent 16ea3ec commit e6f6782
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.2.4

- fix crashes from corrupted sessions

## v1.2.3

- fix memory usage issues when downloading huge files
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rammerhead",
"version": "1.2.3",
"version": "1.2.4",
"description": "User friendly web proxy powered by testcafe-hammerhead",
"main": "src/index.js",
"scripts": {
Expand Down
18 changes: 17 additions & 1 deletion src/classes/RammerheadSessionFileCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class RammerheadSessionFileCache extends RammerheadSessionAbstractStore {
* @param {number} options.cacheTimeout - timeout before saving cache to disk and deleting it from the cache
* @param {number} options.cacheCheckInterval
* @param {boolean} options.deleteUnused - (default: true) if set to true, it deletes unused sessions when saving cache to disk
* @param {boolean} options.deleteCorruptedSessions - (default: true) if set to true, auto-deletes session files that
* give a parse error (happens when nodejs exits abruptly while serializing session to disk)
* @param {object|null} options.staleCleanupOptions - set to null to disable cleaning up stale sessions
* @param {number|null} options.staleCleanupOptions.staleTimeout - stale sessions that are inside saveDirectory that go over
* this timeout will be deleted. Set to null to disable.
Expand All @@ -30,6 +32,7 @@ class RammerheadSessionFileCache extends RammerheadSessionAbstractStore {
cacheTimeout = 1000 * 60 * 20, // 20 minutes
cacheCheckInterval = 1000 * 60 * 10, // 10 minutes,
deleteUnused = true,
deleteCorruptedSessions = true,
staleCleanupOptions = {
staleTimeout: 1000 * 60 * 60 * 24 * 1, // 1 day
maxToLive: 1000 * 60 * 60 * 24 * 4, // four days
Expand All @@ -41,6 +44,7 @@ class RammerheadSessionFileCache extends RammerheadSessionAbstractStore {
this.logger = logger;
this.deleteUnused = deleteUnused;
this.cacheTimeout = cacheTimeout;
this.deleteCorruptedSessions = deleteCorruptedSessions;
/**
* @type {Map.<string, RammerheadSession>}
*/
Expand Down Expand Up @@ -95,7 +99,19 @@ class RammerheadSessionFileCache extends RammerheadSessionAbstractStore {
return this.cachedSessions.get(id);
}

const session = RammerheadSession.DeserializeSession(id, fs.readFileSync(this._getSessionFilePath(id)));
let session;
try {
session = RammerheadSession.DeserializeSession(id, fs.readFileSync(this._getSessionFilePath(id)));
} catch (e) {
if (e.name === 'SyntaxError' && e.message.includes('JSON')) {
this.logger.warn(`(FileCache.get) ${id} bad JSON`);
if (this.deleteCorruptedSessions) {
this.delete(id);
this.logger.warn(`(FileCache.get) ${id} deleted because of bad JSON`);
}
return;
}
}

if (updateActiveTimestamp) {
this.logger.debug(`(FileCache.get) ${id} update active timestamp`);
Expand Down
4 changes: 3 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ module.exports = {
staleTimeout: 1000 * 60 * 60 * 24 * 3, // 3 days
maxToLive: null,
staleCheckInterval: 1000 * 60 * 60 * 6 // 6 hours
}
},
// corrupted session files happens when nodejs exits abruptly while serializing the JSON sessions to disk
deleteCorruptedSessions: true,
},

//// LOGGING CONFIGURATION ////
Expand Down

0 comments on commit e6f6782

Please sign in to comment.