question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ERROR: No server chosen by WritableServerSelector from cluster

See original GitHub issue

Hi, I’m new here and trying to use embedded mongo for webflux integration test using WebTestClient. I guess I have succeed to create embedded mongodb, but it seems not to be connected to the test application or at least it cannot do write operation to db.

Class annotation is:

@WebFluxTest(controllers = {DeveloperApplicationController.class})
@Import({
    DeveloperApplicationService.class,
    UserApplicationBizValidator.class,
    UserApplicationService.class
})
@TestPropertySource(properties = "spring.mongodb.embedded.version=3.2.8")

And I set embedded mongo like this:

    private MongodStarter starter;
    private MongodExecutable mongodExecutable;
    private MongodProcess mongod;

    @BeforeEach
    public void initMock() {
        starter = MongodStarter.getDefaultInstance();
        try {
            String bindIp = "127.0.0.1";
            int port = Network.getFreeServerPort();
            MongodConfig mongodConfig = MongodConfig.builder()
                .version(Version.Main.PRODUCTION)
                .net(new Net(bindIp, port, Network.localhostIsIPv6()))
                .replication(new Storage("/custom/databaseDir", null, 0))
                .build();
            mongodExecutable = starter.prepare(mongodConfig);
            mongod = mongodExecutable.start();

        } catch (Exception e) {
            log.debug("init Mock Error: ", e);
        }

Error message is:

2022-07-14 12:36:55.547 [ll'}-localhost:58458] [DEBUG]      [cluster                                 :56  ] - Checking status of localhost:58458
2022-07-14 12:36:55.549 [ll'}-localhost:58458] [DEBUG]      [cluster                                 :56  ] - Updating cluster description to  {type=REPLICA_SET, servers=[]
2022-07-14 12:36:55.556 [parallel-1          ] [DEBUG]      [ResponseBodyResultHandler               :161 ] - [785426ef] Using 'application/json' given [application/json] and supported [application/json, application/*+json, application/x-ndjson, text/event-stream]
2022-07-14 12:36:55.556 [parallel-1          ] [DEBUG]      [ResponseBodyResultHandler               :167 ] - [785426ef] 0..N [com.naver.gncp.vulkan.common.dto.StoreDto]
2022-07-14 12:36:55.569 [parallel-1          ] [DEBUG]      [ReactiveMongoTemplate                   :1314] - Executing count: { "deleted" : false, "applicationType" : "PRIVATE", "authType" : "SELLER", "identifier" : "test_auth_id_seller"} in collection: applications
2022-07-14 12:36:55.569 [parallel-1          ] [DEBUG]      [ReactiveMongoTemplate                   :1334] - Executing count: { "deleted" : false, "applicationType" : "PRIVATE", "authType" : "SELLER", "identifier" : "test_auth_id_seller"} in collection: applications
2022-07-14 12:36:55.578 [parallel-1          ] [INFO ]      [cluster                                 :71  ] - No server chosen by com.mongodb.reactivestreams.client.internal.ClientSessionHelper$$Lambda$1594/0x0000000300ad6568@2c8656c7 from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:55.579 [parallel-1          ] [DEBUG]      [ReactiveMongoTemplate                   :1314] - Executing count: { "deleted" : false, "applicationType" : "PRIVATE", "authType" : "SELLER", "identifier" : "test_auth_id_seller_2"} in collection: applications
2022-07-14 12:36:55.579 [parallel-1          ] [DEBUG]      [ReactiveMongoTemplate                   :1334] - Executing count: { "deleted" : false, "applicationType" : "PRIVATE", "authType" : "SELLER", "identifier" : "test_auth_id_seller_2"} in collection: applications
2022-07-14 12:36:55.579 [parallel-1          ] [INFO ]      [cluster                                 :71  ] - No server chosen by com.mongodb.reactivestreams.client.internal.ClientSessionHelper$$Lambda$1594/0x0000000300ad6568@1aef316a from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.051 [ll'}-localhost:58458] [DEBUG]      [cluster                                 :56  ] - Checking status of localhost:58458
2022-07-14 12:36:56.054 [ll'}-localhost:58458] [DEBUG]      [cluster                                 :56  ] - Updating cluster description to  {type=REPLICA_SET, servers=[]
2022-07-14 12:36:56.362 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.363 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.364 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.364 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.365 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.513 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.513 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.514 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.514 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.558 [ll'}-localhost:58458] [DEBUG]      [cluster                                 :56  ] - Checking status of localhost:58458
2022-07-14 12:36:56.560 [ll'}-localhost:58458] [DEBUG]      [cluster                                 :56  ] - Updating cluster description to  {type=REPLICA_SET, servers=[]
2022-07-14 12:36:56.573 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.574 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.574 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.574 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.636 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.672 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.673 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.673 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.674 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.674 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.750 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.751 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.752 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.752 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.752 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.879 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.886 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.905 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.906 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:56.906 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:57.060 [ll'}-localhost:58458] [DEBUG]      [cluster                                 :56  ] - Checking status of localhost:58458
2022-07-14 12:36:57.061 [ll'}-localhost:58458] [DEBUG]      [cluster                                 :56  ] - Updating cluster description to  {type=REPLICA_SET, servers=[]
2022-07-14 12:36:57.566 [ll'}-localhost:58458] [DEBUG]      [cluster                                 :56  ] - Checking status of localhost:58458
2022-07-14 12:36:57.567 [ll'}-localhost:58458] [DEBUG]      [cluster                                 :56  ] - Updating cluster description to  {type=REPLICA_SET, servers=[]
2022-07-14 12:36:57.593 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:57.593 [8f555db8a53f3ba31ae6] [INFO ]      [cluster                                 :71  ] - No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, serverDescriptions=[]}. Waiting for 2000 ms before timing out
2022-07-14 12:36:58.067 [ll'}-localhost:58458] [DEBUG]      [cluster                                 :56  ] - Checking status of localhost:58458
2022-07-14 12:36:58.069 [ll'}-localhost:58458] [DEBUG]      [cluster                                 :56  ] - Updating cluster description to  {type=REPLICA_SET, servers=[]
2022-07-14 12:36:58.375 [8f555db8a53f3ba31ae6] [ERROR]      [ReactiveMongoTemplate                   :306 ] - Unexpected exception during asynchronous execution
org.springframework.dao.DataAccessResourceFailureException: Timed out after 2000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=REPLICA_SET, servers=[]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 2000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=REPLICA_SET, servers=[]
	at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:95)
	at org.springframework.data.mongodb.core.ReactiveMongoTemplate.potentiallyConvertRuntimeException(ReactiveMongoTemplate.java:2954)
	at org.springframework.data.mongodb.core.ReactiveMongoTemplate.lambda$translateException$89(ReactiveMongoTemplate.java:2937)
	at reactor.core.publisher.Flux.lambda$onErrorMap$28(Flux.java:6908)
	at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:94)
	at reactor.core.publisher.MonoFlatMapMany$FlatMapManyInner.onError(MonoFlatMapMany.java:255)
	at reactor.core.publisher.FluxConcatArray$ConcatArraySubscriber.onError(FluxConcatArray.java:207)
	at reactor.core.publisher.MonoIgnoreElements$IgnoreElementsSubscriber.onError(MonoIgnoreElements.java:84)
	at reactor.core.publisher.MonoNext$NextSubscriber.onError(MonoNext.java:93)
	at reactor.core.publisher.MonoNext$NextSubscriber.onError(MonoNext.java:93)
	at reactor.core.publisher.MonoFlatMap$FlatMapMain.secondError(MonoFlatMap.java:192)
	at reactor.core.publisher.MonoFlatMap$FlatMapInner.onError(MonoFlatMap.java:259)
	at reactor.core.publisher.MonoPeekTerminal$MonoTerminalPeekSubscriber.onError(MonoPeekTerminal.java:258)
	at reactor.core.publisher.MonoCreate$DefaultMonoSink.error(MonoCreate.java:201)
	at com.mongodb.reactivestreams.client.internal.MongoOperationPublisher.lambda$sinkToCallback$30(MongoOperationPublisher.java:545)
	at com.mongodb.reactivestreams.client.internal.OperationExecutorImpl.lambda$execute$9(OperationExecutorImpl.java:124)
	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:48)
	at com.mongodb.internal.operation.CreateIndexesOperation$2.call(CreateIndexesOperation.java:214)
	at com.mongodb.internal.operation.OperationHelper$AsyncCallableWithConnectionCallback.onResult(OperationHelper.java:666)
	at com.mongodb.internal.operation.OperationHelper$AsyncCallableWithConnectionCallback.onResult(OperationHelper.java:658)
	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:48)
	at com.mongodb.internal.binding.AsyncClusterBinding$2.onResult(AsyncClusterBinding.java:151)
	at com.mongodb.internal.binding.AsyncClusterBinding$2.onResult(AsyncClusterBinding.java:147)
	at com.mongodb.internal.connection.BaseCluster$ServerSelectionRequest.onResult(BaseCluster.java:449)
	at com.mongodb.internal.connection.BaseCluster.handleServerSelectionRequest(BaseCluster.java:320)
	at com.mongodb.internal.connection.BaseCluster.access$700(BaseCluster.java:66)
	at com.mongodb.internal.connection.BaseCluster$WaitQueueHandler.run(BaseCluster.java:499)
	at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: com.mongodb.MongoTimeoutException: Timed out after 2000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=REPLICA_SET, servers=[]
	at com.mongodb.internal.connection.BaseCluster.createTimeoutException(BaseCluster.java:424)
	... 4 common frames omitted

I’ve tried and found lots of answers on google but couldn’t find solution. I need your help please…

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
michaelmosmanncommented, Aug 1, 2022

@broccolism we learn all the time… wish you success:) so i close this… just reopen if needed.

0reactions
broccolismcommented, Jul 25, 2022

@michaelmosmann Okay I got it. I really appreciate your help 😇 I’m gonna try again with my local mongoDB and tell you the result. I guess this issue would not be the problem of this project, it’s just my fault

Read more comments on GitHub >

github_iconTop Results From Across the Web

No server chosen by WritableServerSelector from cluster
Are any permissions missing (because of this WritableServerSelector -Thing)?; Does it has to do with the "test"-database? Are there problems ...
Read more >
No server chosen by WritableServerSelector - MongoDB
Hi, I have Spring backend app connected to Mongodb (configured with MongoDB Kubernetes Operator) on Kubernetes. Sometimes (not for every ...
Read more >
Java – No server chosen by WritableServerSelector from cluster
As a newbie to MongoDB I'm trying to insert a simple document into my freshly installed mongoDB (v3.2.4). MongoDB Driver 3.2.2 is used....
Read more >
Java driver stops connecting to one server after cluster status ...
Java driver stops connecting to one server after cluster status update ... No server chosen by WritableServerSelector from cluster ...
Read more >
mongodb No server chosen by com.mongodb.async.client ...
I want to connect mongodb by use scala , but I got error: `No server chosen by com.mongodb.async.client.ClientSessionHelper$1@8c3b9d from cluster ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found