rocicorp / replicache

Realtime Sync for Any Backend Stack
https://doc.replicache.dev
1.04k stars 37 forks source link

Recursion / infinite loop bug in "delete" #985

Closed tmcw closed 2 years ago

tmcw commented 2 years ago

Encountering the below in prod:

RangeError: Maximum call stack size exceeded
  at ? (./node_modules/replicache/out/replicache.mjs:1:49086)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)
  at delete(./node_modules/replicache/out/replicache.mjs:1:49078)
  at ? (./node_modules/replicache/out/replicache.mjs:1:49188)
  at Array.forEach(<anonymous>)

It looks like there's some recursive code that isn't finding an end condition here.

aboodman commented 2 years ago

Thank you for the report. This looks concerning. @arv is going to look into it soon.

arv commented 2 years ago

@tmcw Which version is this?

arv commented 2 years ago

Assuming v10.0.0-beta.0 I get:

npx stacktracify out/replicache.mjs.map
RangeError: Maximum call stack size exceeded
    at  (../src/dag/lazy-store.ts:489:34)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
    at  (../src/dag/lazy-store.ts:489:26)
    at  (../src/dag/lazy-store.ts:498:15)
    at Array.forEach
arv commented 2 years ago

The only way I think this can happen based on looking at the code is that a chunk is referencing itself. Something that should never happen.

@tmcw I'm going to add some asserts and attach a tarball here that you can try

arv commented 2 years ago

Attached is a new build with asserts as well as the sourcemap for that build.

replicache-10.0.0-beta.0.tgz.zip replicache.mjs.map.zip

arv commented 2 years ago

Fixed