Mailtrain-org / mailtrain

Self hosted newsletter app
GNU General Public License v3.0
5.53k stars 692 forks source link

Error after uploading image in Mosaico #1075

Closed ironhacker closed 8 months ago

ironhacker commented 3 years ago

This happened after attempting to upload an image in a Mosaico template.

node[71324]: info HTTP GET /mosaico/img?method=placeholder&params=258%2C150 200 103.367 ms - -
node[71324]: /opt/mailtrain/server/lib/file-cache.js:155
node[71324]:                             cachedFiles.delete(key);
node[71324]:                             ^
node[71324]: ReferenceError: cachedFiles is not defined
node[71324]:     at /opt/mailtrain/server/lib/file-cache.js:155:29
node[71324]:     at FSReqCallback.oncomplete (fs.js:180:23)
jorge-vitrubio commented 3 years ago

hello where did you look after the mosaico logs apart from /var/log/apache2/? I'm experiencing some issues also, so I would like to look at them.

I have already ask to the Mosaico developers: https://github.com/voidlabs/mosaico/issues/606

jorge-vitrubio commented 3 years ago

well, as explained by the Mosaico developer Bago, the issue on the rest side should be due to the implementation of mossaic, as it is a browser-side javascript library and errors should be looked after with in the browser console.

this is the apache log

192.168.21.2 - - [17/May/2021:14:09:06 +0200] "GET /rest/templates/1 HTTP/1.0" 200 2810
192.168.21.2 - - [17/May/2021:14:09:06 +0200] "POST /rest/permissions-check HTTP/1.0" 200 141
192.168.21.2 - - [17/May/2021:14:09:06 +0200] "POST /rest/send-configurations-with-send-permission-table HTTP/1.0" 200 300
192.168.21.2 - - [17/May/2021:14:09:06 +0200] "GET /rest/namespaces-tree HTTP/1.0" 200 320
192.168.21.2 - - [17/May/2021:14:09:06 +0200] "POST /rest/mosaico-templates-by-tag-language-table/simple HTTP/1.0" 200 144
192.168.21.2 - - [17/May/2021:14:09:06 +0200] "POST /rest/lists-table HTTP/1.0" 200 339
192.168.21.2 - - [17/May/2021:14:09:06 +0200] "POST /rest/mosaico-templates-by-tag-language-table/simple HTTP/1.0" 200 211
192.168.21.2 - - [17/May/2021:14:09:06 +0200] "POST /rest/restricted-access-token HTTP/1.0" 200 50
192.168.21.2 - - [17/May/2021:14:09:09 +0200] "GET /static/mosaico/rs/img/mosaico32.png HTTP/1.0" 200 965
192.168.21.2 - - [17/May/2021:14:09:09 +0200] "GET /mosaico/img?method=placeholder&params=258%2C150 HTTP/1.0" 200 2938
192.168.21.2 - - [17/May/2021:14:09:36 +0200] "PUT /rest/restricted-access-token HTTP/1.0" 500 575
192.168.21.2 - - [17/May/2021:14:09:37 +0200] "GET /mosaico/img?method=placeholder&params=258%2C150 HTTP/1.0" 500 575
192.168.21.2 - - [17/May/2021:14:10:00 +0200] "POST /rest/permissions-check HTTP/1.0" 200 141
192.168.21.2 - - [17/May/2021:14:10:01 +0200] "POST /rest/templates-table HTTP/1.0" 200 261
192.168.21.2 - - [17/May/2021:14:10:02 +0200] "GET /rest/templates/1 HTTP/1.0" 200 2810
192.168.21.2 - - [17/May/2021:14:10:02 +0200] "POST /rest/permissions-check HTTP/1.0" 200 141
192.168.21.2 - - [17/May/2021:14:10:03 +0200] "POST /rest/mosaico-templates-by-tag-language-table/simple HTTP/1.0" 200 144
192.168.21.2 - - [17/May/2021:14:10:03 +0200] "POST /rest/lists-table HTTP/1.0" 200 339
192.168.21.2 - - [17/May/2021:14:10:03 +0200] "POST /rest/send-configurations-with-send-permission-table HTTP/1.0" 200 300
192.168.21.2 - - [17/May/2021:14:10:03 +0200] "POST /rest/restricted-access-token HTTP/1.0" 200 50
192.168.21.2 - - [17/May/2021:14:10:03 +0200] "POST /rest/mosaico-templates-by-tag-language-table/simple HTTP/1.0" 200 211
192.168.21.2 - - [17/May/2021:14:10:03 +0200] "GET /rest/namespaces-tree HTTP/1.0" 200 320
192.168.21.2 - - [17/May/2021:14:10:05 +0200] "GET /static/mosaico/rs/img/mosaico32.png HTTP/1.0" 304 -
192.168.21.2 - - [17/May/2021:14:10:04 +0200] "GET /mosaico/img?method=placeholder&params=258%2C150 HTTP/1.0" 200 2938
192.168.21.2 - - [17/May/2021:14:10:33 +0200] "PUT /rest/restricted-access-token HTTP/1.0" 500 575
192.168.21.2 - - [17/May/2021:14:10:33 +0200] "GET /mosaico/img?method=placeholder&params=258%2C150 HTTP/1.0" 500 575

jus in case some one arrives here asking the same issue:

on browser (FireFox or Chormium/Chrome) open the developer tools / inspector mode (usually F12) select the console (firefox `ctrl+shift+k) and check for errors

then proceed to see what is happening, in my case this is the log

Error: Request failed with status code 500
    createError webpack://MailtrainReactBody/./node_modules/axios/lib/core/createError.js?:16
    settle webpack://MailtrainReactBody/./node_modules/axios/lib/core/settle.js?:17
    handleLoad webpack://MailtrainReactBody/./node_modules/axios/lib/adapters/xhr.js?:61
page.js:561:15
    errorHandler webpack://MailtrainReactBody/./src/lib/page.js?:561
    handleError webpack://MailtrainReactBody/./src/lib/error-handling.js?:22
    handleError webpack://MailtrainReactBody/./src/lib/error-handling.js?:26
    handleError webpack://MailtrainReactBody/./src/lib/error-handling.js?:26
    handleError webpack://MailtrainReactBody/./src/lib/error-handling.js?:26
    handleError webpack://MailtrainReactBody/./src/lib/error-handling.js?:26
    value webpack://MailtrainReactBody/./src/lib/error-handling.js?:72
    asyncGeneratorStep webpack://MailtrainReactBody/./src/lib/error-handling.js?:11
    _throw webpack://MailtrainReactBody/./src/lib/error-handling.js?:13
jorge-vitrubio commented 3 years ago

As I can see the user in /opt/mailtrain/server/files/ is root I need it to be mailtrain:mailtrain and it works but then, as the serivice is runned by the root user it does change to root:root

I don't know how to change this behavour, I have tried to change the service defined in the /etc/systemd/system/ with no sucess: this setting do work

[Unit]
Description=Mailtrain server
After=syslog.target network.target mariadb.service redis-server.service mongod.service

[Service]
Type=simple
Environment="NODE_ENV=production"
WorkingDirectory=/opt/mailtrain/server
ExecStart=/usr/bin/node index.js
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

but if I add the user and group it doesn't

Description=Mailtrain server
After=syslog.target network.target mariadb.service redis-server.service mongod.service

[Service]
Type=simple
User=mailtrain
Group=mailtrain
Environment="NODE_ENV=production"
WorkingDirectory=/opt/mailtrain/server
ExecStart=/usr/bin/node index.js
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

and the user exitst

 id mailtrain
uid=1000(mailtrain) gid=1000(mailtrain) groups=1000(mailtrain)
usrflo commented 3 years ago

I had the same error situation as described above (https://github.com/Mailtrain-org/mailtrain/issues/1075#issue-891144980) and I needed 4 changes to get this to run:

  1. although in server/package.json the dependency on "posix": "^4.1.2" is listed under "optionalDependencies", I needed to setup npm install posix for writing files to server/files/ : with this package, a user change from 'root' to 'mailtrain' is possible when writing files.

  2. as server/files was created with user 'root' beforehand the setup of the npm-posix-package, you need to chown -R server/files

  3. in server/lib/file-cache.js there is an undefined variable "cachedFiles". I think changing cachedFiles.delete(key); to fileCaches.delete(key); is correct to fix this bug.

  4. systemctl restart mailtrain

talheim-it commented 3 years ago

@usrflo thanks, gonna check and fix it when we update the packages.

anibalpacheco commented 1 year ago

Hello, after many hours of investigation and debugging, I observed that the Files are created named with the next id of the file_cache table, but the row inserted in the transaction block, is deleted immediately in the "destroy" block, why?, then , the "prune" task is never triggered because there are not enough rows to reach the prune size limit. Anyone is getting that behavior too? I'll give up trying to fix and I'll make a cron job to remove old files

mojuotalo commented 1 year ago

am having this ay 17 16:06:06 sv-ena-001 node[186132]: info HTTP POST /rest/permissions-check 200 21.678 ms - 85 May 17 16:06:06 sv-ena-001 node[186132]: info HTTP POST /rest/files-table/campaign/file/8 200 8.774 ms - 57 May 17 16:06:08 sv-ena-001 node[186132]: info HTTP GET /rest/campaigns-settings/8 304 14.327 ms - - May 17 16:06:08 sv-ena-001 node[186132]: info HTTP POST /rest/permissions-check 200 16.285 ms - 85

talheim-it commented 8 months ago

We are going to start with the development and testing of mailtrain v3 in the next weeks.

You are welcome to help us with the testing as soon as the first release candidate is available.