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
[BUG] JSQLParser Version : 5.1: CCJSqlParserUtil.parse timeout Not thread-safe #2221
It is also unwise to use an ExecutorService to implement timeouts, forcing the parsing work to be limited by the number of threads in the thread pool
This is an ideal way of implementation, only need to use a global thread ScheduledThreadPoolExecutor whether to mark a timeout, which will help the parse SQL is limited by the ExecutorService number of threads
publicstaticScheduledThreadPoolExecutorscheduledThreadPoolExecutor = newScheduledThreadPoolExecutor(1);
privatestaticfinalVarHandleIVH;
static {
try {
IVH = MethodHandles.lookup().findVarHandle(CCJSqlParser.class, "interrupted", boolean.class);
} catch (NoSuchFieldException | IllegalAccessExceptione) {
thrownewRuntimeException(e);
}
}
publicstaticStatementparseWithTimeOut(CCJSqlParserparser) throwsParseException {
ScheduledFuture<?> schedule = scheduledThreadPoolExecutor.schedule(
() ->{
//todo or use AtomicBoolean.setOpaque or use volatile But there is an additional overhead//todo It's not actually valid Because CCJSqlParser gets interrupted as a normal variableIVH.setOpaque(parser, true)
},
4000, TimeUnit.MILLISECONDS
);
try {
returnparser.Statement();
} finally {
schedule.cancel(false);
}
}
Or just add CCJSqlParser! interrupted is replaced with a check to see if the current time is greater than the timeout, which allows us to disconnect from the thread altogether
Activity
relufi commentedon Apr 8, 2025
It is cross-thread
It is possible for ! interrupted to be inlined into a register, resulting in interrupted always being false
relufi commentedon Apr 8, 2025
It is also unwise to use an ExecutorService to implement timeouts, forcing the parsing work to be limited by the number of threads in the thread pool
This is an ideal way of implementation, only need to use a global thread ScheduledThreadPoolExecutor whether to mark a timeout, which will help the parse SQL is limited by the ExecutorService number of threads
relufi commentedon Apr 8, 2025
Or just add CCJSqlParser! interrupted is replaced with a check to see if the current time is greater than the timeout, which allows us to disconnect from the thread altogether
manticore-projects commentedon Apr 8, 2025
Greetings! Thank you very much for you input which I appreciate a lot. Although your comments are a bit scarce to help my understanding.