Skip to content

Commit

Permalink
Merge pull request #32345 from appsmithorg/cherry-pick/2Apr2024
Browse files Browse the repository at this point in the history
fix: Scheduling synchronized block on bounded elastic threadpool inst…
  • Loading branch information
trishaanand authored Apr 2, 2024
2 parents 24bcef9 + 3d0eec0 commit 3eeb09c
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;

import java.time.Instant;
import java.util.Map;
Expand Down Expand Up @@ -103,7 +104,8 @@ public Mono<? extends DatasourceContext<?>> getCachedDatasourceContextMono(
// Basically remove entry from both cache maps
pluginExecutor.datasourceDestroy(connection);
} catch (Exception e) {
log.info("Error destroying stale datasource connection", e);
log.info(
Thread.currentThread().getName() + ": Error destroying stale datasource connection", e);
}
}
datasourceContextMonoMap.remove(datasourceContextIdentifier);
Expand All @@ -117,7 +119,8 @@ public Mono<? extends DatasourceContext<?>> getCachedDatasourceContextMono(
*/
if (datasourceContextIdentifier.getDatasourceId() != null
&& datasourceContextMonoMap.get(datasourceContextIdentifier) != null) {
log.debug("Cached resource context mono exists. Returning the same.");
log.debug(Thread.currentThread().getName()
+ ": Cached resource context mono exists. Returning the same.");
return datasourceContextMonoMap.get(datasourceContextIdentifier);
}

Expand Down Expand Up @@ -182,11 +185,11 @@ public Mono<Object> updateDatasourceAndSetAuthentication(Object connection, Data

protected Mono<DatasourceContext<?>> createNewDatasourceContext(
DatasourceStorage datasourceStorage, DatasourceContextIdentifier datasourceContextIdentifier) {
log.debug("Datasource context doesn't exist. Creating connection.");
log.debug(Thread.currentThread().getName() + ": Datasource context doesn't exist. Creating connection.");
Mono<Plugin> pluginMono =
pluginService.findById(datasourceStorage.getPluginId()).cache();

return pluginMono
return (Mono<DatasourceContext<?>>) pluginMono
.zipWith(pluginExecutorHelper.getPluginExecutor(pluginMono))
.flatMap(tuple2 -> {
Plugin plugin = tuple2.getT1();
Expand Down Expand Up @@ -214,7 +217,9 @@ protected Mono<DatasourceContext<?>> createNewDatasourceContext(

return getCachedDatasourceContextMono(
datasourceStorage, plugin, pluginExecutor, monitor, datasourceContextIdentifier);
});
})
// Scheduling on bounded elastic to avoid blocking the main thread
.subscribeOn(Schedulers.boundedElastic());
}

public boolean getIsStale(
Expand Down

0 comments on commit 3eeb09c

Please sign in to comment.