riclolsen / json-scada

A portable and scalable SCADA/IIoT-I4.0 platform centered on the MongoDB database server.
https://riclolsen.github.io/json-scada/
GNU General Public License v3.0
272 stars 73 forks source link

BSON Version Conflict in `server_realtime_auth` #141

Closed Zarvhos closed 1 week ago

Zarvhos commented 2 weeks ago

Description

We are experiencing issues with the server_realtime_auth backend service of the json-scada project. The problem manifests when performing certain actions (e.g., creating a new user or role) through the htdocs-admin page. The actions fail intermittently, and the following error is thrown:

throw new BSONVersionError();
                  ^
BSONVersionError: Unsupported BSON version, bson types must be from bson 6.x.x

Steps to Reproduce

Expected Behavior

The actions such as creating new users or roles should execute without throwing errors related to BSON versions.

Technical Details

Running npm list bson reveals a version conflict between dependencies:

├─┬ mongodb@6.8.0
│ └── bson@6.8.0
└─┬ mongoose@6.12.2
  ├── bson@4.7.2
  └─┬ mongodb@4.17.1
    └── bson@4.7.2 deduped

The mongodb package is using bson@6.8.0, while mongoose is using bson@4.7.2. This discrepancy leads to the BSONVersionError.

Possible Solutions

1. Upgrade Mongoose Dependency: Ensure that mongoose is compatible with mongodb and its required BSON version. Refer to the MongoDB Server Version Compatibility matrix here: Mongoose Compatibility

2. Align BSON Versions: Ensure that all dependencies use the same bson version (preferably 6.x.x) to avoid conflicts.

3. Use overrides: In your package.json, use the overrides field to enforce a specific bson version for all dependencies. This can help ensure compatibility and avoid version conflicts.

(Personally I downgraded mongodb to 4.0.0, i'm still testing but the error has disapeared)

References

Mongoose Compatibility

Additional Context

This issue can potentially affect other actions involving BSON serialization/deserialization due to the version mismatch. It is critical to resolve this to ensure the stability and reliability of the server_realtime auth service. Also, this problem might intervene in server_realtime too, to be investigated.

riclolsen commented 1 week ago

Problem confirmed, thanks @Zarvhos for the detailed report. I am testing code changes necessary to update mongo/mongoose npm packages to the latest versions.

riclolsen commented 1 week ago

Fixes were published to the repo.

Zarvhos commented 1 week ago

Thank you, @riclolsen, for the prompt fix. The BSONVersionError issue seems to be resolved now.

Best, Zarvhos