rxdb icon indicating copy to clipboard operation
rxdb copied to clipboard

RXServer - nodejs PayloadTooLargeError: request entity too large

Open fadnincx opened this issue 8 months ago • 9 comments

Yesterday using our software, based on RXDB with RXServer (Express) as backend, on a bigger live event than before, we suddenly experienced failed synchronizations. All the affected client was receiving was 413 Request entity too large. A look at the backend logs revealed, it was continuously throwing nodejs PayloadTooLargeError: request entity too large errors. Looking for the cause, it seems express limits json parsing by default to 1mb.

So as a dirty workaround, in RxServerAdapterExpress, create(), I changed app.use(express.json()); to app.use(express.json({limit: '500mb'})); and thing recovered.

Once app.use(express.json()); is called in the RxServerAdapterExpress function, further calls with different options are ignored.

Since (as far as I see), there currently is no possibility to give custom options to the Express adapter, what would be you're preferred design (@pubkey).

Or is there a (to me unknown) option on the client side to restrict the payload size?

fadnincx avatar Apr 25 '25 16:04 fadnincx

This issue has been automatically marked as stale because it has not had recent activity. It will be closed soon. Please update it or it may be closed to keep our repository organized. The best way is to add some more information or make a pull request with a test case. Also you might get help in fixing it at the RxDB Community Chat If you know you will continue working on this, just write any message to the issue (like "ping") to remove the stale tag.

stale[bot] avatar May 02 '25 17:05 stale[bot]

This should be made possible. PR is welcomed.

pubkey avatar May 03 '25 09:05 pubkey

@pubkey here a PR using the appOptions variable.

fadnincx avatar May 03 '25 12:05 fadnincx

This issue has been automatically marked as stale because it has not had recent activity. It will be closed soon. Please update it or it may be closed to keep our repository organized. The best way is to add some more information or make a pull request with a test case. Also you might get help in fixing it at the RxDB Community Chat If you know you will continue working on this, just write any message to the issue (like "ping") to remove the stale tag.

stale[bot] avatar May 17 '25 13:05 stale[bot]

@pubkey do you need any more information? Can I help? Or what's the blocker here?

fadnincx avatar May 18 '25 06:05 fadnincx

@fadnincx I checked and I cannot merge this. This would only work for the express based server adapter, not for fastify and koa. It should be possible to get the express instance in your own code and set the json limit after the server has been created?

pubkey avatar May 21 '25 09:05 pubkey

@pubkey that was exactly why I was asking

what would be you're preferred design

I'm using the express instance in my code to provide different API endpoints besides RXDB. Until now, I was not able to successfully set the limit after the server has been created.

So another way I see would be, to give the user the possibility to submit it's own instance to the adapter.

fadnincx avatar May 24 '25 08:05 fadnincx

Yes I think that would be the best solution. The adapter is only a few lines of code, so you would copy that and add any options there.

pubkey avatar May 24 '25 21:05 pubkey

This issue has been automatically marked as stale because it has not had recent activity. It will be closed soon. Please update it or it may be closed to keep our repository organized. The best way is to add some more information or make a pull request with a test case. Also you might get help in fixing it at the RxDB Community Chat If you know you will continue working on this, just write any message to the issue (like "ping") to remove the stale tag.

stale[bot] avatar May 31 '25 22:05 stale[bot]

Issues are autoclosed after some time. If you still have a problem, make a PR with a test case or to prove that you have tried to fix the problem.

stale[bot] avatar Jun 21 '25 23:06 stale[bot]