title: Akka - Sender[null] sent message of type
body: <p>I have a spray route where I declare one of my actors.</p>
  
  <pre><code>val myActor = actorRefFactory.actorSelection("/user/my-actor")
  </code></pre>
  
  <p>And my route looks like:</p>
  
  <pre><code>get {
    path(Segment / Segment) { (poolId, trackId) =&gt;
      respondWithMediaType(MediaTypes.`application/json`) {
        val request = Request(poolId, trackId)
  
        val f = (myActor ? request)
          .recoverWith {
            case a: AskTimeoutException =&gt;
              Future.failed[StandardRoute](throw new Exception(s"We got a timeout", a))
  
            case e: Exception =&gt; Future.failed[StandardRoute](throw new Exception(s"We got an error", e))
          }
  
        onComplete(f) {
          case Success(resp) =&gt; complete(OK, resp)
  
          case Failure(e) =&gt;
            log.error(s"Fatal request error: $trackId / $poolId", e)
            complete(InternalServerError, ErrorCodes.ErrorNotHandled)
        }
      }
    }
  }
  </code></pre>
  
  <p>Sometimes, I can see when I get lots of requests at the same time, some of them may fail with the following message:</p>
  
  <blockquote>
    <p>Caused by: akka.pattern.AskTimeoutException: Ask timed out on
    [ActorSelection[Anchor(akka://default/), Path(/user/my-actor)]] after
    [8000 ms]. Sender[null] sent message of type
    "my.company.messages.Request".</p>
  </blockquote>
  
  <p>The problem is if I take the same request and try to send it again, it works, only sometimes this happens and I have no idea how to solve that.</p>
  
  <p>The actor indeed is doing a lot of things with lots of futures inside until it returns a value to the spray route.</p>
  
  <p>Inside the actor, I create a val called replyTo in order to keep the value of the sender.</p>
  
  <p>Any ideas on why sometimes I get this error?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Just an example on how I'm managing the myActor:</p>
  
  <pre><code>class MyActor extends Actor with ActorLogging {
  
    private implicit val timeout = Timeout(8.seconds)
  
    def receive = {
  
      case req: Request =&gt;
  
        val replyTo = sender()
  
        doOneThing.map { one =&gt;
  
          doSecondThing(one).map { sec =&gt;
            replyTo ! sec
          }
        }
    }
  }
  </code></pre>
  
  <p>Where doOneThing and doSecondThing are Futures... and I have a lot of them spread around this actor for different situations.</p>