I'm using scrooge + thrift to generate my server and client code. Everything is working just fine so far.
Here's a simplified example of how I use my client:
private lazy val client =
Thrift.newIface[MyPingService[Future]](s"$host:$port")
def main(args: Array[String]): Unit = {
logger.info("ping!")
client.ping().foreach { _ =>
logger.info("pong!")
// TODO: close client
sys.exit(0)
}
}
Everything is working just fine, but the server complains when the program exits about unclosed connections. I've looked all over but I can't seem to figure out how to close the client instance.
So my question is, how do you close a Finagle thrift client? I feel like I'm missing something obvious.
As far as I know, when you use the automagic
Thrift.newIface[Iface]method to create your service, you can't close it, because the only thing that your code knows about the resulting value is that it conforms toIface. If you need to close it, you can instantiate your client in two steps, creating the Thrift service in one and adapting it to your interface in the other.Here's how it looks if you're using Scrooge to generate your Thrift interface:
I tried this in the repl, and it worked for me. Here's a lightly-edited transcript:
This is not too bad, but I hope there's a better way that I don't know yet.