turt2live / matrix-dimension

An open source integration manager for matrix clients, like Element.
https://dimension.t2bot.io
GNU General Public License v3.0
433 stars 110 forks source link

Error: Can't set headers after they are sent. #281

Open airblag opened 5 years ago

airblag commented 5 years ago

I found the same errors in the issues #275 and #240 but I cannot say exactly where it comes from in my installation (updated to commit be66dd04f977ec13dc4dd41a9914a7f7fa821647).

Every time I switch room in riot, the following error comes 3 times

Mai 03 12:53:01 mort npm[23994]: May-3-2019 12:53:01.690 +02:00 info [Webserver] Incoming request: GET /api/v1/scalar/account?scalar_token=redacted&v=1.1
Mai 03 12:53:02 mort npm[23994]: Error: Can't set headers after they are sent.
Mai 03 12:53:02 mort npm[23994]:     at SendStream.headersAlreadySent (/home/dimension/matrix-dimension/node_modules/send/index.js:390:13)
Mai 03 12:53:02 mort npm[23994]:     at SendStream.send (/home/dimension/matrix-dimension/node_modules/send/index.js:618:10)
Mai 03 12:53:02 mort npm[23994]:     at onstat (/home/dimension/matrix-dimension/node_modules/send/index.js:730:10)
Mai 03 12:53:02 mort npm[23994]:     at FSReqWrap.oncomplete (fs.js:154:5)

Some times it appears only once.

I didn't found any problem related to this error on the user side.

Dimension is running behind nginx.

Is it a bug or did I miss something ?

turt2live commented 5 years ago

The error is normally harmless - are you seeing any other side effects?

airblag commented 5 years ago

no, i don't see anything not working because of that, but it's filling my log files :)

yingziwu commented 3 years ago

The error is normally harmless - are you seeing any other side effects?

I found this error will cause that transmission is closed early.

This will cause Failed to load sticker packs error on Your Sticker Packs page.

image

Console log:

{…}
​
error: Object { error: SyntaxError, text: "[{\"id\":1,\"displayName\":\"Huskies\",\"avatarUrl\":\"mxc://t2bot.io/193408b58f5e1eb72d9bea13f23914e6\",\"description\":\"The most photogenic animal on the planet.\",\"isEnabled\":true,\"author\":{\"type\":\"none\",\"name\":null,\"reference\":null},\"license\":{\"name\":\"GPL-v3.0\",\"urlPath\":\"/licenses/gpl-v3.0.txt\"},\"stickers\":[{\"id\":1,\"name\":\"Happy\",\"description\":\"A very happy husky\",\"image\":{\"mxc\":\"mxc://t2bot.io/b4636e93388542f3cad8fcbb825adf36\",\"mimetype\":\"image/png\"},\"thumbnail\":{\"mxc\":\"mxc://t2bot.io/920b7a90c8d66f0de0bc2e4e7f1b3d90\",\"width\":512,\"height\":512}},{\"id\":2,\"name\":\"Laughing\",\"description\":\"A husky laughs at something presumably funny\",\"image\":{\"mxc\":\"mxc://t2bot.io/12e39b87ce8099ff5951b9c37405bac5\",\"mimetype\":\"image/png\"},\"thumbnail\":{\"mxc\":\"mxc://t2bot.io/cf2a8f9179bdb59ec3dfdc15a71eb12d\",\"width\":512,\"height\":512}},{\"id\":3,\"name\":\"Sad\",\"description\":\"This husky is sad :(\",\"image\":{\"mxc\":\"mxc://t2bot.io/96777697c144918fe80fca92c90e3208\",\"mimetype\":\"image/png\"},\"thumbnail\":{\"mxc\":\"mxc://t2bot.io/af…" }
​
headers: Object { normalizedNames: Map(0), lazyUpdate: null, lazyInit: lazyInit() }
​
message: "Http failure during parsing for https://dimension.bgme.me/api/v1/dimension/stickers/packs?scalar_token=[token]"
​
name: "HttpErrorResponse"
​
ok: false
​
status: 200
​
statusText: "OK"
​
url: "https://dimension.bgme.me/api/v1/dimension/stickers/packs?scalar_token=[token]"
​
<prototype>: Object { constructor: e(e) }
stickerpicker.component.ts:43:20

Environment

debian version: 10.7
nodejs version: v15.6.0
npm version: 7.4.0
dimension version: 404371fe9d492ef934bca51d38fe2e6d9088a060

Reproduction process

Run the following command on the same machine of dimension:

watch -d "curl -v --connect-to ::192.168.100.1:8184  "http://dimension.bgme.bid/api/v1/dimension/stickers/packs?scalar_token=[token]" 1>/dev/null "

You will get the following results:

normal:

curl -v --connect-to ::192.168.100.1:8184  http://dimension.bgme.bid/api/v1/dimension/stickers/packs?scalar_token=IiZBW4DZQZ287Vr9sBnDvq7vd 1>/...  git: Mon Jan 25 10:58:57 2021

* Expire in 0 ms for 6 (transfer 0x5568e0ba9f90)
* Connecting to hostname: 192.168.100.1
* Connecting to port: 8184
*   Trying 192.168.100.1...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x5568e0ba9f90)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to 192.168.100.1 (192.168.100.1) port 8184 (#0)
> GET /api/v1/dimension/stickers/packs?scalar_token=IiZBW4DZQZ287Vr9sBnDvq7vd HTTP/1.1
> Host: dimension.bgme.bid
> User-Agent: curl/7.64.0
> Accept: */*
>
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization
< Content-Type: application/json; charset=utf-8
< Content-Length: 169598
< ETag: W/"2967e-l3+xBmGWM4sf7W+6cdgvCMWXWtc"
< Date: Mon, 25 Jan 2021 10:58:57 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
<
{ [44689 bytes data]
*100  165k  100  165k    0     0  4732k      0 --:--:-- --:--:-- --:--:-- 4732k
* Connection #0 to host 192.168.100.1 left intact

error:

curl -v --connect-to ::192.168.100.1:8184  http://dimension.bgme.bid/api/v1/dimension/stickers/packs?scalar_token=IiZBW4DZQZ287Vr9sBnDvq7vd 1>/...  git: Mon Jan 25 10:58:09 2021

* Expire in 0 ms for 6 (transfer 0x564d649e7f90)
* Connecting to hostname: 192.168.100.1
* Connecting to port: 8184
*   Trying 192.168.100.1...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x564d649e7f90)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to 192.168.100.1 (192.168.100.1) port 8184 (#0)
> GET /api/v1/dimension/stickers/packs?scalar_token=IiZBW4DZQZ287Vr9sBnDvq7vd HTTP/1.1
> Host: dimension.bgme.bid
> User-Agent: curl/7.64.0
> Accept: */*
>
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization
< Content-Type: application/json; charset=utf-8
< Content-Length: 169598
< ETag: W/"2967e-l3+xBmGWM4sf7W+6cdgvCMWXWtc"
< Date: Mon, 25 Jan 2021 10:58:10 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
<
{ [44689 bytes data]
* transfer closed with 57325 bytes remaining to read
* 66  165k   66  109k    0     0  4568k      0 --:--:-- --:--:-- --:--:-- 4568k
* Closing connection 0
curl: (18) transfer closed with 57325 bytes remaining to read
rakshazi commented 3 years ago

Hello, tried to work with Dimension on element android and got error "User does not have permissions", but i use admin user and i can do that on element web.

The error in log:

Feb 14 15:52:36 matrix matrix-dimension[26675]: Error: Can't set headers after they are sent.
Feb 14 15:52:36 matrix matrix-dimension[26675]:     at SendStream.headersAlreadySent (/home/node/matrix-dimension/node_modules/send/index.js:390:13)
Feb 14 15:52:36 matrix matrix-dimension[26675]:     at SendStream.send (/home/node/matrix-dimension/node_modules/send/index.js:617:10)
Feb 14 15:52:36 matrix matrix-dimension[26675]:     at onstat (/home/node/matrix-dimension/node_modules/send/index.js:729:10)
Feb 14 15:52:36 matrix matrix-dimension[26675]:     at FSReqCallback.oncomplete (fs.js:167:5)
IF-Adin commented 3 years ago

I have the same problem. Stickers do not work for me at all. They all return a 502.

IF-Adin commented 3 years ago

Jun 12 18:48:21 matrix-dimension[20622]: Error: Can't set headers after they are sent. Jun 12 18:48:21 matrix-dimension[20622]: at SendStream.headersAlreadySent (/home/node/matrix-dimension/node_modules/send/index.js:390:13) Jun 12 18:48:21 matrix-dimension[20622]: at SendStream.send (/home/node/matrix-dimension/node_modules/send/index.js:617:10) Jun 12 18:48:21 matrix-dimension[20622]: at onstat (/home/node/matrix-dimension/node_modules/send/index.js:729:10)

This completely block the displaying of all stickers. Federation is set up correctly and the federation tester as well as the extension tester work fine.

pratikbin commented 2 years ago

I'm seeing this and then https://github.com/turt2live/matrix-dimension/issues/471

gaelgatelement commented 2 years ago

Same error after setting a k8s probe on the dimension pod :

          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /api/v1/dimension/health/heartbeat
              port: 8184
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 10
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /api/v1/dimension/health/heartbeat
              port: 8184
              scheme: HTTP
            initialDelaySeconds: 2
            periodSeconds: 3
Tue, 22 Mar 2022 18:29:02 GMT [INFO] [DimensionHealthService] Heartbeat called
Error: Can't set headers after they are sent.
    at SendStream.headersAlreadySent (/home/node/matrix-dimension/node_modules/send/index.js:390:13)
    at SendStream.send (/home/node/matrix-dimension/node_modules/send/index.js:617:10)
    at onstat (/home/node/matrix-dimension/node_modules/send/index.js:729:10)
    at FSReqCallback.oncomplete (fs.js:193:5)
PeterCxy commented 2 years ago

FYI: This error is NOT harmless -- send will close the stream when this error happens. It does not manifest for most users because there is a reverse proxy either on localhost or on a LAN, which will normally complete the read way before the stream is actually closed. However, if theere is even just a bit of a delay between the reverse proxy and the matrix-dimension server, this will result in the response not being sent in full, and thus the client will receive a corrupted JSON. The fix described in #442 should fix most of the issues mentioned above.