Skip to content
This repository has been archived by the owner on Nov 4, 2021. It is now read-only.

Babel Loop Timeouts #155

Merged
merged 53 commits into from
Feb 18, 2021
Merged

Babel Loop Timeouts #155

merged 53 commits into from
Feb 18, 2021

Conversation

mariusandra
Copy link
Collaborator

@mariusandra mariusandra commented Feb 15, 2021

Changes

  • All plugin JS is now processed via @babel/standalone. This unlocks cool stuff like native TS support in the future. We might also look into caching the processed code.
  • I've added a babel plugin that injects code into all for, while and do while loops, as described in this article using a babel plugin modified from one published by jsbin. Basically we'll check at the beginning of the loop and throw an error if it has been running too long.

This greatly decreases our risk against some of the attacks described in #57 . This does not yet protect us against long running promises nor "out of memory" scenarios. These could be built in to this PR or done later with another PR, we'll see how it goes.

This might also have some implications and might need to be dialled down for scheduled plugins like runEveryHour, where you might actually want a long running for loop.

Checklist

  • Updated Settings section in README.md, if settings are affected
  • Jest tests

@mariusandra mariusandra requested a review from Twixes February 16, 2021 16:30
@mariusandra
Copy link
Collaborator Author

Had some trouble with tests in the end, but good to go. I added some extra metrics in the end as well.

Copy link
Member

@Twixes Twixes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Postgres suite stalls after merging with master… but besides that this is 👌

@mariusandra
Copy link
Collaborator Author

There's one flaky test where it expects one number to be 32, but sometimes it's 33 or 34. So for now I'll just rerun the tests and hope they pass :).

@mariusandra mariusandra merged commit b235de3 into master Feb 18, 2021
@mariusandra mariusandra deleted the babel-timeouts branch February 18, 2021 07:52
This was referenced Feb 18, 2021
fuziontech pushed a commit to PostHog/posthog that referenced this pull request Oct 12, 2021
* transpile code via babel-standalone

* move vm.ts into vm/

* add TASK_TIMEOUT config

* add babel transform to timeout while loops

* update refactored rename

* vm while timeout test

* add more unimplemented timeout tests

* add transforms for while/for/do-while loops

* fix loop timeout ms

* remove extra ;

* fix import

* fix more imports

* fix even more imports

* fix error messages

* simplify errors

* small refactor

* fix import

* add async guard and protect against long promises

* async guard around setupPlugin()

* add column

* slightly safer variables

* less noise in vm bench

* can not override async guard for the main functions (e.g. processEvent, etc)

* reduce how much we do in a benchmark

* add types to loop timeout

* types for promise timeout

* fix line/column numbers

* explain some decisions

* verify that the process event timeout applies e2e.

* managed to get equal, so changing

* update message that it's just a warning

* add e2e kafka test for bad delay

* shorter test in github action

* increase test timeout to see if that makes a difference (locally it takes 3min for both tests)

* skip the "slow on GH action" test for now

* process kafka events in parallel by default

* add more metrics to kafka queue

* some debug to help fix the test

* add debug log in the delayUntilEventIngested function

* add "single_event_batch" timing to the event processing steps

* fix timer

* Improve timeoutGuard default timeout

* revert benchmark to the last one that worked

* skip bad delay

* add back a 1:1 copy of the e2e.kafka test, but with the timeout code. see if GH actions run

* remove broken tests, improve logging of working tests

* Clan up vm.ts

* Improve clarity of loopTimeout

* Refactor transforms slightly

* Refactor transform call to secureCode func

* Add secureCode tests

Co-authored-by: Michael Matloka <dev@twixes.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants