Skip to content

Intermittent DB File Locking Error with mqtt-jsonl-store in mac with Vitest/WebStorm Environment  #36

@Evilu

Description

@Evilu

Package Version: 0.2.1
WebStorm Version: WebStorm 2024.2.0.1
Node.js Version: v22.9.0
OS Version:

ProductName:    macOS  
ProductVersion: 13.1  
BuildVersion:   22C65  

Vitest Version: 2.1.8


Problem Description

When running tests using vitest in WebStorm, an intermittent error occurs when attempting to lock the database file incoming.jsonl. This issue seems to manifest after the first successful test run.

Error Stack Trace

Error: Failed to lock DB file "incoming.jsonl"!
    at JsonlDB.open (/Users/myname/Desktop/coding/proj/service1/node_modules/@alcalzone/jsonl-db/src/lib/db.ts:407:10)
    at async Promise.all (index 0)
    at Manager.open (/Users/myname/Desktop/coding/proj/service1/node_modules/mqtt-jsonl-store/src/lib/manager.ts:36:3)
    at Module.createMqttConnection (/Users/myname/Desktop/coding/proj/service1/services/Iot_Service/iotServiceMain.ts:19:3)
    at Module.initializeMqttConnection (/Users/myname/Desktop/coding/proj/service1/services/mqtt/main.ts:12:18)
    at Module.watchAndSync (/Users/myname/Desktop/coding/proj/service1/services/rabbitMq/main.ts:11:5)
    at /Users/myname/Desktop/coding/proj/service1/tests/RABBIT_TO_CLOUD_TESTS/service1.test.ts:34:5
    at async Promise.all (index 0)
    at callSuiteHook (file:///Users/myname/Desktop/coding/proj/service1/node_modules/@vitest/runner/dist/index.js:700:23)
    at runSuite (file:///Users/myname/Desktop/coding/proj/service1/node_modules/@vitest/runner/dist/index.js:892:27)

Implementation Details

Below is the relevant implementation of the mqtt-jsonl-store usage:

import { Manager } from 'mqtt-jsonl-store';
import crypto from 'crypto';

export async function createMqttConnection(configs: Configs, key: string, cert: string, ca: string) {
  try {
    const randomClientId = crypto.randomBytes(8).toString('hex');
    const manager = new Manager('./');
    await manager.open();

    const options = {
      clean: false,
      incomingStore: manager.incoming,
      outgoingStore: manager.outgoing,
      clientId: randomClientId,
      protocol: 'mqtt',
      host: 'somehost.iot.us-east-1.amazonaws.com',
      key: key,
      cert: cert,
      ca: ca
    };

    return mqqtjs.connect(configs.endpointUrl, options);
  } catch (error) {
    console.log(error);
  }
}

Additional Context

  • The issue only occurs with vitest when using WebStorm's implementation.
  • Behavior:
    • First test run: No error.
    • Subsequent test runs: Error occurs intermittently.
  • Observed that waiting exactly 1:30 minutes between test launches prevents the error.
  • The incoming.jsonl file lock seems to persist between test runs when the time interval between test executions is short.

Expected Behavior

  • The database file incoming.jsonl should lock and unlock correctly between test executions without manual time delays.

Steps to Reproduce

  1. Run a test suite involving mqtt-jsonl-store in WebStorm.
  2. Re-run the test immediately after the first run.
  3. Observe the intermittent error related to incoming.jsonl file locking.

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions