You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mysql: Leaking of prepared statements when using opentelemetry #18975
One side-issue in relation to this is the actual limit if you don't specify the statement_cache_size seems to be 700, but the documentation states it should be 100.
I'm not aware of the intracises of passing comments to a prepared statement in terms of what is a cache hit or not, so assuming that it's not possible to pass the span id to a prepared statement as an argument (and therefore operating the cache at a high hit-ratio), for DX purposes it might have saved my production server from outage by having statement_cache_size somehow default to 0 (disabled) whenever opentelemetry is active.
Upon reflecting this would appear to be an impossible technical task - MySQL doesn't seem to support ? as a placeholder in comments. This makes sense.
What doesn't make sense is the combination of Prisma defaults along with the sample code for opentelemtry tracing. On a DX level, my suggestions are:
Add a big warning to the opentracing code to state this is not suitable for production without some extra considerations.
A bit hacky I admit.. but Prisma could recognise that @prisma/instrumentation is modifying the SQL query and to adjust the internal fallback default for statement_cache_size to 0. This is because we know for sure that every single query will be unique, busting the whole benefit of cache.
The only idea I have is could the tracing comment be attached to the CALL statement instead of the PREPARE STATEMENT statement? Then you could strip the comment before adding into the cache. If this somehow works, my PoC would show max "1" stored procedure on the server at all times.
Still happens on Prisma 5.1.1. Smaller reproduction:
import{PrismaClient}from'@prisma/client'import{registerInstrumentations}from'@opentelemetry/instrumentation'import{NodeTracerProvider}from'@opentelemetry/sdk-trace-node'import{PrismaInstrumentation}from'@prisma/instrumentation'constprovider=newNodeTracerProvider()registerInstrumentations({tracerProvider: provider,instrumentations: [newPrismaInstrumentation()],})provider.register()asyncfunctionmain(){constprisma=newPrismaClient()for(leti=0;i<10;i++){awaitprisma.user.findMany()console.log(awaitprisma.$queryRaw`SHOW GLOBAL STATUS LIKE '%prepared_stmt_count%';`)}}main()
Test performs prisma query and outputs total number of prepared queries:
One can see that number of prepared statements grows with each iterations.
If we comment out proveder.register() or new PrismaInstrumentation() line, output stays consistent:
changed the title [-]Leaking of prepared statements when using opentelemetry[/-][+]mysql: Leaking of prepared statements when using opentelemetry[/+]on Aug 7, 2023
Activity
janpio commentedon Apr 27, 2023
What is the influence of OpenTelemetry?
Why do you expect the number of prepared statements to stay at 1?
binary64 commentedon Apr 27, 2023
One side-issue in relation to this is the actual limit if you don't specify the
statement_cache_sizeseems to be 700, but the documentation states it should be 100.binary64 commentedon Apr 27, 2023
I'm not aware of the intracises of passing comments to a prepared statement in terms of what is a cache hit or not, so assuming that it's not possible to pass the span id to a prepared statement as an argument (and therefore operating the cache at a high hit-ratio), for DX purposes it might have saved my production server from outage by having statement_cache_size somehow default to 0 (disabled) whenever opentelemetry is active.
binary64 commentedon Apr 27, 2023
The output I was seeing from the mysql general_log was:
The hash changes every query
jkomyno commentedon Apr 28, 2023
Internal: this other issue could shed light on what OP is reporting.
binary64 commentedon Apr 28, 2023
Upon reflecting this would appear to be an impossible technical task - MySQL doesn't seem to support
?as a placeholder in comments. This makes sense.What doesn't make sense is the combination of Prisma defaults along with the sample code for opentelemtry tracing. On a DX level, my suggestions are:
The only idea I have is could the tracing comment be attached to the CALL statement instead of the PREPARE STATEMENT statement? Then you could strip the comment before adding into the cache. If this somehow works, my PoC would show max "1" stored procedure on the server at all times.
SevInf commentedon Aug 4, 2023
Still happens on Prisma 5.1.1. Smaller reproduction:
Test performs prisma query and outputs total number of prepared queries:
One can see that number of prepared statements grows with each iterations.
If we comment out
proveder.register()ornew PrismaInstrumentation()line, output stays consistent:Note that it it happens even if
tracingpreview feature is not enabled.[-]Leaking of prepared statements when using opentelemetry[/-][+]mysql: Leaking of prepared statements when using opentelemetry[/+]