-
Couldn't load subscription status.
- Fork 245
fix: read-after-write issues #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,14 +8,18 @@ import Fastify from 'fastify'; | |
| import metricsPlugin from 'fastify-metrics'; | ||
|
|
||
| import { generateId } from '@openpanel/common'; | ||
| import type { IServiceClientWithProject } from '@openpanel/db'; | ||
| import { getRedisPub } from '@openpanel/redis'; | ||
| import { | ||
| type IServiceClientWithProject, | ||
| runWithAlsSession, | ||
| } from '@openpanel/db'; | ||
| import { getCache, getRedisPub } from '@openpanel/redis'; | ||
| import type { AppRouter } from '@openpanel/trpc'; | ||
| import { appRouter, createContext } from '@openpanel/trpc'; | ||
|
|
||
| import { | ||
| EMPTY_SESSION, | ||
| type SessionValidationResult, | ||
| decodeSessionToken, | ||
| validateSessionToken, | ||
| } from '@openpanel/auth'; | ||
| import sourceMapSupport from 'source-map-support'; | ||
|
|
@@ -140,7 +144,14 @@ const startServer = async () => { | |
| instance.addHook('onRequest', async (req) => { | ||
| if (req.cookies?.session) { | ||
| try { | ||
| const session = await validateSessionToken(req.cookies.session); | ||
| const sessionId = decodeSessionToken(req.cookies.session); | ||
| const session = await runWithAlsSession(sessionId, () => | ||
| sessionId | ||
| ? getCache(`validateSession:${sessionId}`, 60 * 5, async () => | ||
| validateSessionToken(req.cookies.session), | ||
| ) | ||
| : validateSessionToken(req.cookies.session), | ||
| ); | ||
|
Comment on lines
+147
to
+154
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainALS context is limited to validation; make it request‐scoped for non‐TRPC routes.
Prefer entering ALS for the entire request after you derive
I can provide a small helper and wire‐up if useful. Run to confirm coverage (expect TRPC covered; verify non‐TRPC): 🏁 Script executed: #!/bin/bash # TRPC ALS coverage rg -n --hidden -g '!**/dist/**' 'sessionScopeMiddleware|runWithAlsSession\(' packages/trpc # Non‐TRPC dashboard routes touching DB that may lack ALS rg -n --hidden -g '!**/dist/**' -C2 'db\.' apps/api/src/routes -g '!**/trpc/**' Length of output: 401 🏁 Script executed: #!/bin/bash # Check structure of apps/api/src to understand route organization echo "=== Directory structure of apps/api/src ===" fd -t f -e ts -e js apps/api/src --max-depth 3 # Search for route definitions/handlers in apps/api/src (more permissive pattern) echo "=== Potential route handlers in apps/api/src ===" rg -n --hidden -g '!**/dist/**' "app\.(get|post|put|patch|delete|use)\(|router\." apps/api/src | head -30 # Check if non-TRPC routes access database echo "=== Non-TRPC files with db access ===" rg -n --hidden -g '!**/dist/**' -g '!**/trpc/**' "db\." apps/api/src | head -20 # Look at index.ts to understand the endpoint structure echo "=== Line count context around 147-154 in index.ts ===" wc -l apps/api/src/index.ts Length of output: 2163 🏁 Script executed: #!/bin/bash # View the validation code and surrounding context echo "=== index.ts lines 130-200 (full context around 147-154) ===" sed -n '130,200p' apps/api/src/index.ts # Find where controllers are imported/used echo "=== Controller imports and usage in index.ts ===" rg -n 'controller|Controller' apps/api/src/index.ts | head -20 # Check if there's a middleware that sets ALS at request level echo "=== Middleware patterns in index.ts ===" rg -n --hidden -g '!**/dist/**' "middleware|use\(|als\." apps/api/src/index.ts | head -20 Length of output: 2551 ALS context is limited to validation; extend it to request-scoped for non-TRPC routes. The TRPC is properly covered by its own Recommend one of:
🤖 Prompt for AI Agents |
||
| if (session.session) { | ||
| req.session = session; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { createLogger } from '@openpanel/logger'; | ||
|
|
||
| export const logger = createLogger({ name: 'db:prisma' }); |