loopingz / smtp-relay

SMTP Toolbox
GNU Lesser General Public License v3.0
29 stars 3 forks source link

Error: ENOENT: no such file or directory, unlink #67

Closed jangrewe closed 9 months ago

jangrewe commented 9 months ago

Describe the bug We're running smtp-relay in Docker on an EC2 instance, and the container regularly crash with this error (but varying filenames, of course):

Sep 12 07:17:10 gitlab docker[1603915]: node:fs:1883
Sep 12 07:17:10 gitlab docker[1603915]:   handleErrorFromBinding(ctx);
Sep 12 07:17:10 gitlab docker[1603915]:   ^
Sep 12 07:17:10 gitlab docker[1603915]: Error: ENOENT: no such file or directory, unlink '.email_20230912T071709979Z.eml'
Sep 12 07:17:10 gitlab docker[1603915]:     at Module.unlinkSync (node:fs:1883:3)
Sep 12 07:17:10 gitlab docker[1603915]:     at PassThrough.<anonymous> (file:///smtp-relay/lib/server.js:188:20)
Sep 12 07:17:10 gitlab docker[1603915]:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
Sep 12 07:17:10 gitlab docker[1603915]:   errno: -2,
Sep 12 07:17:10 gitlab docker[1603915]:   syscall: 'unlink',
Sep 12 07:17:10 gitlab docker[1603915]:   code: 'ENOENT',
Sep 12 07:17:10 gitlab docker[1603915]:   path: '.email_20230912T071709979Z.eml'
Sep 12 07:17:10 gitlab docker[1603915]: }
Sep 12 07:17:10 gitlab docker[1603915]: Node.js v18.17.1

The majority of mail it accepts gets handled without any issues, but this happens every once in a while (e.g. twice in 12 hours now).

To Reproduce Steps to reproduce the behavior:

  1. run smtp-relay
  2. send mails (in our case from GitLab, but i don't think this matters)
  3. See error

Expected behavior Emails get relayed and the container keeps running.

loopingz commented 9 months ago

The only unlink used in the server code is here:

    // @ts-ignore
    stream.on("end", async () => {
      await this.filter("Data", session, [session]);
      session.email = await simpleParser(fs.createReadStream(session.emailPath));
      await this.onDataRead(session);
      if (!this.config.keepCache) {
        fs.unlinkSync(session.emailPath);
      }
      callback();
    });

I'm still unsure why it cannot delete it, I will update code to have a try/catch around the unlink today, in the mean time you can try to add a keepCache: true to your configuration

jangrewe commented 9 months ago

Thanks, i've added this to the config and will keep an eye on the log and any updates. 😃

loopingz commented 9 months ago

The 1.3.3 version should not have the issue, please keep me update, and if you like the project please star it. It helps with visibility

jangrewe commented 9 months ago

Thank you! I've just deployed the updated image and now i'm waiting for the first error (without crash), but i'm confident that your changes will be doing what they're supposed to. 😀