Skip to content

Commit

Permalink
remove Statsig.shutdown() (#791)
Browse files Browse the repository at this point in the history
### Description

Removes `Statsig.shutdown()` from middleware.

Calling Statsig.shutdown leads to a race condition when multiple
requests happen to the same middleware:
- Request A calls `await Statsig.initialize()`
- Request B calls `await Statsig.initialize()`
- Request A calls `Statsig.shutdown()` destroying the singleton
- Request B tries to use Statsig but the singleton is no longer
initialized

This leads to the following error being thrown

```
Error: Call and wait for initialize() to finish first.
    at (node_modules/.pnpm/statsig-node@5.9.3/node_modules/statsig-node/dist/Errors.js:22:27)
    at (node_modules/.pnpm/statsig-node@5.9.3/node_modules/statsig-node/dist/StatsigServer.js:532:27)
    at (node_modules/.pnpm/statsig-node@5.9.3/node_modules/statsig-node/dist/StatsigServer.js:523:30)
    at (node_modules/.pnpm/statsig-node@5.9.3/node_modules/statsig-node/dist/StatsigServer.js:463:22)
    at (node_modules/.pnpm/statsig-node@5.9.3/node_modules/statsig-node/dist/StatsigServer.js:224:70)
    at (node_modules/.pnpm/statsig-node@5.9.3/node_modules/statsig-node/dist/ErrorBoundary.js:27:25)
    at (node_modules/.pnpm/statsig-node@5.9.3/node_modules/statsig-node/dist/StatsigServer.js:224:35)
    at (node_modules/.pnpm/statsig-node@5.9.3/node_modules/statsig-node/dist/index.js:160:37)
    at (middleware.ts:33:27)
    at (node_modules/.pnpm/next@13.4.20-canary.30_react-dom@18.2.0+react@18.2.0/node_modules/next/dist/esm/server/web/adapter.js:150:19)
```
  • Loading branch information
dferber90 committed Sep 15, 2023
1 parent 77524d9 commit 01f237d
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions edge-middleware/ab-testing-statsig/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ export async function middleware(req: NextRequest, event: NextFetchEvent) {
}

// Flush exposure logs to Statsig
event.waitUntil(
Statsig.flush().then(() => {
Statsig.shutdown()
})
)
event.waitUntil(Statsig.flush())

return res
}

39 comments on commit 01f237d

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

edge-api-routes-json-response – ./edge-api-routes/json-response

edge-api-routes-json-response.vercel.app
edge-api-routes-json-response-git-main.vercel.sh
edge-api-routes-json-response.vercel.sh

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

edge-api-routes-query-parameters – ./edge-api-routes/query-parameters

edge-api-routes-query-parameters.vercel.app
edge-api-routes-query-parameters.vercel.sh
edge-api-routes-query-parameters-git-main.vercel.sh

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

edge-api-routes-hello-world – ./edge-api-routes/hello-world

edge-api-route.vercel.app
edge-api-routes-hello-world-git-main.vercel.sh
edge-api-routes-hello-world.vercel.sh

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

edge-api-routes-cache-control – ./edge-api-routes/cache-control

edge-api-routes-cache-control.vercel.app
edge-api-routes-cache-control-git-main.vercel.sh
edge-api-routes-cache-control.vercel.sh

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

redirect-with-fallback – ./app-directory/redirect-with-fallback

redirect-with-fallback.vercel.app
redirect-with-fallback-git-main-vercel-solutions-vtest314.vercel.app
redirect-with-fallback-vercel-solutions-vtest314.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

edge-functions-authed-proxy – ./edge-api-routes/authed-proxy

authed-proxy.vercel.app
edge-functions-authed-proxy.vercel.sh
edge-functions-authed-proxy-git-main.vercel.sh

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

postgres-starter – ./storage/postgres-starter

postgres-starter.vercel.app
postgres-starter-vercel-labs.vercel.app
postgres-starter-git-main-vercel-labs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

solutions-testing – ./solutions/testing/apps/main-site

solutions-testing-vercel-solutions-vtest314.vercel.app
solutions-testing-git-main-vercel-solutions-vtest314.vercel.app
solutions-testing.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

wasm-rust-hello-world – ./edge-api-routes/wasm-rust-hello-world

wasm-rust-hello-world.vercel.app
wasm-rust-hello-world-git-main-vercel-solutions-vtest314.vercel.app
wasm-rust-hello-world-vercel-solutions-vtest314.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

examples – ./storage/postgres-starter

examples-bice.vercel.app
examples-git-main-vercel-labs.vercel.app
examples-vercel-labs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

wasm-rust-xor – ./edge-api-routes/wasm-rust-xor

wasm-rust-xor.vercel.app
wasm-rust-xor-vercel-solutions-vtest314.vercel.app
wasm-rust-xor-git-main-vercel-solutions-vtest314.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

blob-starter – ./storage/blob-starter

blob-starter.vercel.app
blob-starter-vercel-labs.vercel.app
blob-starter-git-main-vercel-labs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

next-flask – ./python/nextjs-flask

next-flask-vercel-labs.vercel.app
next-flask-git-main-vercel-labs.vercel.app
nextjs-python.vercel.app
nextjs-flask-starter.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

solutions-image-offset – ./solutions/image-offset

solutions-image-offset-now-examples.vercel.app
solutions-image-offset-git-main-now-examples.vercel.app
solutions-image-offset.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

edge-functions-news – ./starter/next-news

edge-functions-next-news.vercel.sh
edge-functions-news-now-examples.vercel.app
edge-functions-news-git-main-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

edge-user-agent-based-rendering – ./edge-middleware/user-agent-based-rendering

edge-user-agent-based-rendering-git-main-now-examples.vercel.app
edge-user-agent-based-rendering.vercel.app
edge-user-agent-based-rendering-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

edge-ab-testing-statsig – ./edge-middleware/ab-testing-statsig

edge-ab-testing-statsig-now-examples.vercel.app
edge-ab-testing-statsig.vercel.sh
edge-ab-testing-statsig.vercel.app
edge-ab-testing-statsig-git-main-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

solutions-script-component-ad – ./solutions/script-component-ad

solutions-script-component-ad-now-examples.vercel.app
solutions-script-component-ad.vercel.app
solutions-script-component-ad-git-main-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

solutions-loading-web-fonts – ./solutions/loading-web-fonts

solutions-loading-web-fonts-now-examples.vercel.app
solutions-loading-web-fonts-git-main-now-examples.vercel.app
solutions-loading-web-fonts.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

solutions-microfrontends – ./solutions/microfrontends/apps/main

solutions-microfrontends-git-main-now-examples.vercel.app
solutions-microfrontends-now-examples.vercel.app
solutions-microfrontends.vercel.app
microfrontends.vercel.sh

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

i18n – ./edge-middleware/i18n

i18n-now-examples.vercel.app
i18n-git-main-now-examples.vercel.app
middleware-i18n.vercel.app
i18n.vercel.sh

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

app-dir-i18n – ./app-directory/i18n

app-dir-i18n-git-main-now-examples.vercel.app
app-dir-i18n-now-examples.vercel.app
app-dir-i18n.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

app-dir-share-state – ./app-directory/share-state

app-dir-share-state-now-examples.vercel.app
app-dir-share-state.vercel.app
app-dir-share-state-git-main-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

app-dir-css-in-js – ./app-directory/css-in-js

app-dir-css-in-js.vercel.app
app-dir-css-in-js-now-examples.vercel.app
app-dir-css-in-js-git-main-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

edge-middleware-modify-request-header – ./edge-middleware/modify-request-header

edge-middleware-modify-request-header-git-main-now-examples.vercel.app
edge-middleware-modify-request-header-now-examples.vercel.app
edge-middleware-modify-request-header.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

edge-geolocation-country-block – ./edge-middleware/geolocation-country-block

edge-geolocation-country-block-now-examples.vercel.app
edge-geolocation-country-block-git-main-now-examples.vercel.app
edge-geolocation-country-block.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 01f237d Sep 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

nodejs-api – ./solutions/node-hello-world

nodejs-api-murex.vercel.app
nodejs-api-example.vercel.app
nodejs-api-now-examples.vercel.app
nodejs-api-git-main-now-examples.vercel.app

Please sign in to comment.