Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Akka-grpc server stops immediately after running #1536

Open
9claudiu opened this issue Dec 30, 2021 · 8 comments
Open

Akka-grpc server stops immediately after running #1536

9claudiu opened this issue Dec 30, 2021 · 8 comments

Comments

@9claudiu
Copy link

I've created a simple GRPC server as in the documentation.

val registerService: HttpRequest => Future[HttpResponse] =
     RegisterServiceHandler(new RegisterImpl())

     val binding = Http().newServerAt(interface = "127.0.0.1", port = port).bind(registerService)

     binding.foreach { binding => println(s"gRPC server bound to: ${binding.localAddress}") }
     binding

I have the following protobuf which makes akka generate the interfaces

syntax = "proto3";

option java_multiple_files = true;
option java_package = "cityfeed.application.grpc";
option java_outer_classname = "AuthenticationProto";

package auth;

service RegisterService {
  rpc RegisterUser (RegisterRequest) returns (RegisterResponse) {}
}

message RegisterRequest {
  string email_address = 1;
  string username = 2;
  string full_name = 3;
  string password = 4;
  string address = 5;
  string city = 6;
  string neighborhood = 7;
}

message RegisterResponse {
  bool registerSuccess = 1;
}

And as for my implementation, it looks like this:

class RegisterImpl(implicit mat: Materializer) extends RegisterService with LazyLogging {
  override def registerUser(request: RegisterRequest): Future[RegisterResponse] = {
    val credentials = UserCredentials(UUID.randomUUID(), request.username, request.emailAddress, request.password)
    val user = User(None, request.fullName, request.city, request.address, request.neighborhood, credentials)

    val responseIO = for {
      insertedRows <- userRepository.insertUser(user)
    } yield insertedRows

    responseIO.attempt.map {
      case Right(rows) =>
        logger.info(s"Inserted $rows rows")
        new RegisterResponse(true)
      case Left(e) =>
        logger.error(s"User registration failed because of error: ${e.getMessage}")
        new RegisterResponse(false)
    }.unsafeToFuture()
  }
}

When I'm running the server everything goes well, but the server stops immediately, it doesn't listen for calls. I'm not sure if it's an akka related issue, it could be sbt related, but I'm trying my luck here.

@9claudiu
Copy link
Author

It seems it was indeed a sbt related issue, I've downgraded sbt version from 1.6.1 to 1.5.2

@raboof
Copy link
Member

raboof commented Jan 3, 2022

Thanks for the report! If you don't mind I'd like to keep this issue open, since indeed I see the same issue with https://github.com/akka/akka-grpc-quickstart-scala.g8 , and we do want that to work :)

@raboof raboof reopened this Jan 3, 2022
@raboof
Copy link
Member

raboof commented Jan 3, 2022

Looks like this is indeed a change in behavior in sbt that might go away again in the future, tracked in sbt/sbt#6767 .

@raboof
Copy link
Member

raboof commented Jan 3, 2022

As an alternative to downgrading sbt, I can recommend using https://github.com/spray/sbt-revolver/ and starting your application from the sbt console. Perhaps we should consider recommending this in our docs as well?

@raboof
Copy link
Member

raboof commented Jan 3, 2022

Ah, or you could set fork := true, no further changes necessary

@9claudiu
Copy link
Author

9claudiu commented Jan 3, 2022

nice, thank you for your suggestions @raboof
it would be nice to find it also in the docs

@kkurt
Copy link

kkurt commented Apr 3, 2022

I have same issue with akka-grp-server... Is there any progress?

@raboof
Copy link
Member

raboof commented Apr 4, 2022

I have same issue with akka-grp-server... Is there any progress?

The status is still that you can fix it by setting fork := true and that it'd be nice to add this to the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants