Unable to create Client-Side Field Level Encryption enabled connection client with ATLAS in Java

I’ve been facing an issue in creating CSFLE enabled client with MongoDB ATLAS Cluster. The regularClient connection works fine with ATLAS without any issue. I have even created the Key Vault and the Data Key and stored it on ATLAS using the regularClient connection. But when trying to create a CSFLE Enabled Client connection the program fails with “Time out error”. we are using Java and deploying the code in Linux container. I doubt on my docker file setup. due to wrong setup mongocryptd process is not running I guess. can someone please share me sample docker file. thanks in advance.

@Stennie / @wan, can you please help me on this query. thanks in advance.

Hi @PrasannaVengadesan_santhanagopalan, and welcome to the forums!

But when trying to create a CSFLE Enabled Client connection the program fails with “Time out error”

Could you share:

  • A minimum reproducible code
  • Error log (stack trace)

As the “time out error” in this case could be caused by various different reasons, i.e. no mongocryptd available on PATH, etc.

I doubt on my docker file setup. due to wrong setup mongocryptd process is not running I guess. can someone please share me sample docker file

You can have a look at github.com/sindbach/field-level-encryption-docker/java for MongoDB Java sync driver running client-side field level encryption example with a Dockerfile (ubuntu).

Regards,
Wan

1 Like

Thank you so much @wan. I will refer the sample docker file and try it out. also, I will share the error details.

@wan, below is the error message. We are using Mongo Atlas connection string. we have also added commands on docker file to install Mongo Enterprise version. As per Logs, it is installed successfully. but am not sure whether MongoCryptd process is running or not. when we try to insert the records, we are getting below error.

com.mongodb.MongoClientException: Exception in encryption library: Exception in encryption library: Timed out after 1000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27020, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]"

Hi @PrasannaVengadesan_santhanagopalan,

[{address=localhost:27020, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused

This error message means that the driver is unable to establish connection to the mongocryptd (default port 27020). I’d suggest to check whether:

  • mongocryptd is on the PATH, and it’s running
  • The application is able to connect to the port

Regards,
Wan.

1 Like

@wan , I have tried my level best. but now I am running out of idea. In our code we have checked whether MongoCryptd is available on the installed path “/usr/bin/mongocryptd” . it is available. Also, we have started the process by using java code Process process = runTime.exec("/usr/bin/mongocryptd");.

Even after doing all this, when we tried to insert the records on to collection, am getting below error. please suggest me what else I can try. thanks in advance.

“Exception in encryption library: Exception in encryption library: Timed out after 1000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27020, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]”,“severity”:“FAIL”}]}

@wan , can you please provide any help on the issue which I am facing.

Hi @PrasannaVengadesan_santhanagopalan

Also, we have started the process by using java code Process process = runTime.exec("/usr/bin/mongocryptd");.

You don’t need to execute mongocryptd manually, as long as it is in the PATH that should work.

Would you be able to share your Dockerfile and a simple application example, so that others could reproduce your issue ?

Regards,
Wan.

1 Like