diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceContextServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceContextServiceCEImpl.java index 3fa73f2f2a..1004185572 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceContextServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceContextServiceCEImpl.java @@ -24,6 +24,7 @@ import lombok.extern.slf4j.Slf4j; 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; @@ -103,7 +104,8 @@ public class DatasourceContextServiceCEImpl implements DatasourceContextServiceC // 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); @@ -117,7 +119,8 @@ public class DatasourceContextServiceCEImpl implements DatasourceContextServiceC */ 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); } @@ -182,11 +185,11 @@ public class DatasourceContextServiceCEImpl implements DatasourceContextServiceC protected Mono> 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 pluginMono = pluginService.findById(datasourceStorage.getPluginId()).cache(); - return pluginMono + return (Mono>) pluginMono .zipWith(pluginExecutorHelper.getPluginExecutor(pluginMono)) .flatMap(tuple2 -> { Plugin plugin = tuple2.getT1(); @@ -214,7 +217,9 @@ public class DatasourceContextServiceCEImpl implements DatasourceContextServiceC return getCachedDatasourceContextMono( datasourceStorage, plugin, pluginExecutor, monitor, datasourceContextIdentifier); - }); + }) + // Scheduling on bounded elastic to avoid blocking the main thread + .subscribeOn(Schedulers.boundedElastic()); } public boolean getIsStale(