Skip to content

[Bug]: Server crashes at startup with "Region is missing" when USE_LOCAL=true (S3 client built at module import) #2261

Description

@stingeer007

Issue Description

On a fresh self-hosted deployment using local file storage (USE_LOCAL=true), the server container crash-loops at startup with Error: Region is missing.

The cause is in apps/OpenSignServer/cloud/customRoute/deleteAccount/deleteFileUrl.js. The S3 client is constructed at module scope, so it runs on every import regardless of the storage backend:

const s3 = createS3Client({
  region: process.env.DO_REGION,
  endpoint: process.env.DO_ENDPOINT,
  accessKeyId: process.env.DO_ACCESS_KEY_ID,
  secretAccessKey: process.env.DO_SECRET_ACCESS_KEY,
});

index.js correctly falls back to FSFilesAdapter when USE_LOCAL === 'true', but this module is imported through the custom routes anyway, and @aws-sdk/client-s3 throws when region is empty or undefined.

Expected Behavior

With USE_LOCAL=true and no S3 / DigitalOcean Spaces credentials configured, the server should start normally. The S3 client should only be created when it is actually needed.

Current Behavior

The container exits during boot and never binds port 8080:

> open_sign_server@2.37.0 start
> node index.js

/usr/src/app/node_modules/coherentpdf/coherentpdf.js:1007
throw a}function
^

Error: Region is missing
    at resolveRegionConfig (/usr/src/app/node_modules/@smithy/core/dist-cjs/submodules/config/index.js:618:15)
    at new S3Client (/usr/src/app/node_modules/@aws-sdk/client-s3/dist-cjs/index.js:4891:27)
    at createS3Client (file:///usr/src/app/cloud/customRoute/deleteAccount/deleteFileUrl.js:26:10)
    at file:///usr/src/app/cloud/customRoute/deleteAccount/deleteFileUrl.js:29:12
    at ModuleJob.run (node:internal/modules/esm/module_job:271:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:578:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)

Node.js v22.14.0

Steps to reproduce

  1. Deploy opensign/opensignserver:main following the documented docker setup.
  2. In the environment, set USE_LOCAL=true and leave DO_REGION, DO_ENDPOINT, DO_SPACE, DO_ACCESS_KEY_ID and DO_SECRET_ACCESS_KEY empty or unset, since no object storage is used.
  3. Start the server. It crash-loops with the trace above and never serves /app.

Note: the shipped .env.local_dev sets DO_REGION=us-west, which is why the default quickstart does not hit this. Any deployment that clears the S3 variables because it uses local storage does.

Workaround

Set DO_REGION to any non-empty value (for example us-east-1) even when storage is local. The client is then constructed but never used, and the server boots fine.

Suggested fix

Create the client lazily so nothing is built unless a request actually needs S3:

let s3;
function getS3Client() {
  if (!s3) {
    s3 = createS3Client({
      region: process.env.DO_REGION,
      endpoint: process.env.DO_ENDPOINT,
      accessKeyId: process.env.DO_ACCESS_KEY_ID,
      secretAccessKey: process.env.DO_SECRET_ACCESS_KEY,
    });
  }
  return s3;
}

Alternatively, skip S3 deletion entirely when process.env.USE_LOCAL === 'true'.

Happy to send a PR if the lazy-init approach looks right to you.

Operating System

Ubuntu 24.04, Docker Swarm, self-hosted behind Caddy.

What browsers are you seeing the problem on?

Not browser related, the crash is server-side at boot.

What version of OpenSign™ are you seeing this issue on?

2.37.0 (image opensign/opensignserver:main)

What environment are you seeing the problem on?

Hosted (app.yourdomain.com)

Please check the boxes that apply to this issue report.

  • I have searched the existing issues & discussions to make sure that this is not a duplicate.

Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I have searched the existing issues & discussions to make sure that this is not a duplicate.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions