imapflow 1.0.157 → 1.0.158

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.158](https://github.com/postalsys/imapflow/compare/v1.0.157...v1.0.158) (2024-03-19)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **locking:** log extra information about locks ([9790ec5](https://github.com/postalsys/imapflow/commit/9790ec575f405820d05dd4777987a88e0a4e819d))
9
+
3
10
  ## [1.0.157](https://github.com/postalsys/imapflow/compare/v1.0.156...v1.0.157) (2024-03-19)
4
11
 
5
12
 
@@ -21,7 +21,7 @@ async function runIdle(connection) {
21
21
  src: 'c',
22
22
  msg: `DONE`,
23
23
  comment: `breaking IDLE`,
24
- lockId: connection.currentLockId,
24
+ lockId: connection.currentLock?.lockId,
25
25
  path: connection.mailbox && connection.mailbox.path
26
26
  });
27
27
  connection.write('DONE');
@@ -44,7 +44,7 @@ async function runIdle(connection) {
44
44
 
45
45
  connection.log.trace({
46
46
  msg: 'Requesting IDLE break',
47
- lockId: connection.currentLockId,
47
+ lockId: connection.currentLock?.lockId,
48
48
  path: connection.mailbox && connection.mailbox.path,
49
49
  queued: preCheckWaitQueue.length,
50
50
  doneRequested,
@@ -74,7 +74,7 @@ async function runIdle(connection) {
74
74
  if (typeof connection.preCheck === 'function') {
75
75
  connection.log.trace({
76
76
  msg: 'Clearing pre-check function',
77
- lockId: connection.currentLockId,
77
+ lockId: connection.currentLock?.lockId,
78
78
  path: connection.mailbox && connection.mailbox.path,
79
79
  queued: preCheckWaitQueue.length,
80
80
  doneRequested,
package/lib/imap-flow.js CHANGED
@@ -211,7 +211,7 @@ class ImapFlow extends EventEmitter {
211
211
  this.state = this.states.NOT_AUTHENTICATED;
212
212
 
213
213
  this.lockCounter = 0;
214
- this.currentLockId = 0;
214
+ this.currentLock = false;
215
215
 
216
216
  this.tagCounter = 0;
217
217
  this.requestTagMap = new Map();
@@ -2844,7 +2844,13 @@ class ImapFlow extends EventEmitter {
2844
2844
  msg: 'Mailbox locking queued',
2845
2845
  path: this.mailbox && this.mailbox.path,
2846
2846
  pending: this.locks.length,
2847
- idling: this.idling
2847
+ idling: this.idling,
2848
+ activeLock: this.currentLock
2849
+ ? {
2850
+ lockId: this.currentLock.lockId,
2851
+ ...(this.currentLock.options?.description && { description: this.currentLock.options?.description })
2852
+ }
2853
+ : null
2848
2854
  });
2849
2855
  return;
2850
2856
  }
@@ -2861,20 +2867,21 @@ class ImapFlow extends EventEmitter {
2861
2867
  this.processingLock = true;
2862
2868
 
2863
2869
  const release = () => {
2864
- if (this.currentLockId) {
2870
+ if (this.currentLock) {
2865
2871
  this.log.trace({
2866
2872
  msg: 'Mailbox lock released',
2867
- lockId: this.currentLockId,
2873
+ lockId: this.currentLock.lockId,
2868
2874
  path: this.mailbox && this.mailbox.path,
2869
2875
  pending: this.locks.length,
2870
2876
  idling: this.idling
2871
2877
  });
2872
- this.currentLockId = 0;
2878
+ this.currentLock = false;
2873
2879
  }
2874
2880
  this.processLocks(true).catch(err => this.log.error({ err, cid: this.id }));
2875
2881
  };
2876
2882
 
2877
- const { resolve, reject, path, options, lockId } = this.locks.shift();
2883
+ const lock = this.locks.shift();
2884
+ const { resolve, reject, path, options, lockId } = lock;
2878
2885
 
2879
2886
  if (!this.usable || this.socket.destroyed) {
2880
2887
  this.log.trace({ msg: 'Failed to acquire mailbox lock', path, lockId, idling: this.idling });
@@ -2887,15 +2894,27 @@ class ImapFlow extends EventEmitter {
2887
2894
 
2888
2895
  if (this.mailbox && this.mailbox.path === path && !!this.mailbox.readOnly === !!options.readOnly) {
2889
2896
  // nothing to do here, already selected
2890
- this.log.trace({ msg: 'Mailbox lock acquired', path, lockId, idling: this.idling });
2891
- this.currentLockId = lockId;
2897
+ this.log.trace({
2898
+ msg: 'Mailbox lock acquired [existing]',
2899
+ path,
2900
+ lockId,
2901
+ idling: this.idling,
2902
+ ...(options.description && { description: options.description })
2903
+ });
2904
+ this.currentLock = lock;
2892
2905
  return resolve({ path, release });
2893
2906
  } else {
2894
2907
  try {
2895
2908
  // Try to open. Throws if mailbox does not exists or can't open
2896
2909
  await this.mailboxOpen(path, options);
2897
- this.log.trace({ msg: 'Lock acquired', path, lockId, idling: this.idling, ...(options.description && { description: options.description }) });
2898
- this.currentLockId = lockId;
2910
+ this.log.trace({
2911
+ msg: 'Mailbox lock acquired [selected]',
2912
+ path,
2913
+ lockId,
2914
+ idling: this.idling,
2915
+ ...(options.description && { description: options.description })
2916
+ });
2917
+ this.currentLock = lock;
2899
2918
  return resolve({ path, release });
2900
2919
  } catch (err) {
2901
2920
  if (err.responseStatus === 'NO') {
@@ -2909,7 +2928,14 @@ class ImapFlow extends EventEmitter {
2909
2928
  }
2910
2929
  }
2911
2930
 
2912
- this.log.trace({ msg: 'Failed to acquire mailbox lock', path, lockId, idling: this.idling });
2931
+ this.log.trace({
2932
+ msg: 'Failed to acquire mailbox lock',
2933
+ path,
2934
+ lockId,
2935
+ idling: this.idling,
2936
+ ...(options.description && { description: options.description }),
2937
+ err
2938
+ });
2913
2939
  reject(err);
2914
2940
  await this.processLocks(true);
2915
2941
  }
@@ -2943,7 +2969,18 @@ class ImapFlow extends EventEmitter {
2943
2969
  path = normalizePath(this, path);
2944
2970
 
2945
2971
  let lockId = ++this.lockCounter;
2946
- this.log.trace({ msg: 'Requesting lock', path, lockId, ...(options.description && { description: options.description }) });
2972
+ this.log.trace({
2973
+ msg: 'Requesting lock',
2974
+ path,
2975
+ lockId,
2976
+ ...(options.description && { description: options.description }),
2977
+ activeLock: this.currentLock
2978
+ ? {
2979
+ lockId: this.currentLock.lockId,
2980
+ ...(this.currentLock.options?.description && { description: this.currentLock.options?.description })
2981
+ }
2982
+ : null
2983
+ });
2947
2984
 
2948
2985
  return await new Promise((resolve, reject) => {
2949
2986
  this.locks.push({ resolve, reject, path, options, lockId });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imapflow",
3
- "version": "1.0.157",
3
+ "version": "1.0.158",
4
4
  "description": "IMAP Client for Node",
5
5
  "main": "./lib/imap-flow.js",
6
6
  "scripts": {