ciscoheat / sveltekit-rate-limiter

A modular rate limiter for SvelteKit. Use in password resets, account registration, etc.
MIT License
216 stars 3 forks source link

Doesn't quite function when using Bun as a runtime #5

Open W2Wizard opened 8 months ago

W2Wizard commented 8 months ago

I'm not 100% sure if it's necessarily the fault of this lib itself but I haven't been too successful in terms of boiling it down as to what exactly is the problem.

Basically if you use the bun runtime using: https://github.com/gornostay25/svelte-adapter-bun suddenly when submitting any form requests the response is stuck pending endlessly.

To reproduce simply swap out the adapter with the one I listed above and run with: bun --bun run dev, click on the submit button and watch it load forever.

I used this repo to conduct the test and I was using the latest (0.5.2) adapter for bun.


Somewhere within this function the problems start. https://github.com/ciscoheat/sveltekit-rate-limiter/blob/0466070755d8458f3defb376df33b01888288df2/src/lib/server/index.ts#L406-L409

I even tried commenting out the 2 funtions that reference the event, no success. The funny part is, it actually works! As in rate-limiting is being applied if exceeded but the response is somehow lost.

ciscoheat commented 7 months ago

Tested with the latest version of everything (on Windows), and this simple page works fine at least:

import type { PageServerLoad } from './$types';
import { error } from '@sveltejs/kit';
import { RateLimiter } from 'sveltekit-rate-limiter/server';

const limiter = new RateLimiter({
    IP: [3, '10s']
});

export const load = (async (event) => {
    if (await limiter.isLimited(event)) throw error(429);
    return {};
}) satisfies PageServerLoad;

If you have a more advanced case that doesn't work, post a link to its repo and I'll take a look.