Skip to content

Commit

Permalink
GUI project does not receive suggestion database (#9634)
Browse files Browse the repository at this point in the history
close #9558

the `InvalidateModulesIndexCommand` may be waiting for the execution lock, while the handler times out.
  • Loading branch information
4e6 authored Apr 8, 2024
1 parent 07793f5 commit ab552ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ final class SuggestionsHandler(
import context.dispatcher
import SuggestionsHandler._

private val timeout = config.executionContext.requestTimeout

override def preStart(): Unit = {
logger.info(
"Starting suggestions handler from [{}, {}].",
Expand Down Expand Up @@ -357,7 +355,6 @@ final class SuggestionsHandler(
val handler = context.system.actorOf(
InvalidateModulesIndexHandler.props(
RuntimeFailureMapper(contentRootManager),
timeout,
runtimeConnector,
self
)
Expand Down Expand Up @@ -454,7 +451,6 @@ final class SuggestionsHandler(
val handler = context.system.actorOf(
InvalidateModulesIndexHandler.props(
runtimeFailureMapper,
timeout,
runtimeConnector,
self
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import org.enso.languageserver.util.UnhandledLogging
import org.enso.polyglot.runtime.Runtime.Api

import java.util.UUID
import scala.concurrent.duration.FiniteDuration
import scala.concurrent.duration._

/** A request handler for invalidate modules index command.
*
* @param runtimeFailureMapper mapper for runtime failures
* @param timeout request timeout
* @param runtime reference to the runtime connector
* @param suggestionsHandler reference to the suggestions handler
* @param timeout soft request timeout for detecting abnormal behavior
*/
final class InvalidateModulesIndexHandler(
runtimeFailureMapper: RuntimeFailureMapper,
timeout: FiniteDuration,
runtime: ActorRef,
suggestionsHandler: ActorRef
suggestionsHandler: ActorRef,
timeout: FiniteDuration
) extends Actor
with LazyLogging
with UnhandledLogging {
Expand All @@ -34,22 +34,30 @@ final class InvalidateModulesIndexHandler(

private def requestStage: Receive = {
case SearchProtocol.InvalidateModulesIndex =>
runtime ! Api.Request(
val request = Api.Request(
UUID.randomUUID(),
Api.InvalidateModulesIndexRequest()
)
runtime ! request
val cancellable =
context.system.scheduler.scheduleOnce(timeout, self, RequestTimeout)
context.become(responseStage(sender(), cancellable))
context.become(responseStage(sender(), request, cancellable))
}

private def responseStage(
replyTo: ActorRef,
request: Api.Request,
cancellable: Cancellable
): Receive = {
case RequestTimeout =>
replyTo ! RequestTimeout
context.stop(self)
logger.warn(
"Failed to receive a [{}] response in [{}].",
request,
timeout
)
val newCancellable =
context.system.scheduler.scheduleOnce(timeout, self, RequestTimeout)
context.become(responseStage(replyTo, request, newCancellable))

case Api.Response(_, Api.InvalidateModulesIndexResponse()) =>
suggestionsHandler ! SearchProtocol.ClearSuggestionsDatabase
Expand All @@ -69,22 +77,22 @@ object InvalidateModulesIndexHandler {
/** Creates a configuration object used to create [[InvalidateModulesIndexHandler]].
*
* @param runtimeFailureMapper mapper for runtime failures
* @param timeout request timeout
* @param runtime reference to the runtime connector
* @param suggestionsHandler reference to the suggestions handler
* @param timeout soft request timeout for detecting abnormal behavior
*/
def props(
runtimeFailureMapper: RuntimeFailureMapper,
timeout: FiniteDuration,
runtime: ActorRef,
suggestionsHandler: ActorRef
suggestionsHandler: ActorRef,
timeout: FiniteDuration = 30.seconds
): Props =
Props(
new InvalidateModulesIndexHandler(
runtimeFailureMapper,
timeout,
runtime,
suggestionsHandler
suggestionsHandler,
timeout
)
)
}

0 comments on commit ab552ab

Please sign in to comment.