Closed ruslansennov closed 7 years ago
the problem happens with keep-alive.
what is the code creating the HttpClient ?
does it happen inside the same verticle or from a main/test method ?
does it happen inside the same verticle or from a main/test method ?
It happens from a test methods but there is issue in vertx-consul-client
with the same problem.
I made some experiments with ConsulConfigStoreTest:
@Test
public void getSimpleConfig(TestContext tc) {
Async async = tc.async();
createRetriever();
System.out.println(Vertx.currentContext()); // (1)
client.putValue("foo/bar", "value", ar -> {
System.out.println(Vertx.currentContext()); // (2)
tc.assertTrue(ar.succeeded());
retriever.getConfig(json2 -> {
System.out.println(Vertx.currentContext()); // (3)
assertThat(json2.succeeded()).isTrue();
JsonObject config2 = json2.result();
tc.assertTrue(!config2.isEmpty());
tc.assertEquals(config2.getString("bar"), "value");
client.deleteValues("foo", h -> async.complete());
});
});
}
If I run the test by executing the entire class, I see the above warning and:
mvn test -Dtest=ConsulConfigStoreTest
(1) null
WARNING: Reusing a connection with a different context: an HttpClient is probably shared between different Verticles
(2) io.vertx.core.impl.EventLoopContext@1ba3412b
(3) io.vertx.core.impl.EventLoopContext@37c2490c
WARNING: Reusing a connection with a different context: an HttpClient is probably shared between different Verticles
But if I run the getSimpleConfig
test only, then I see no warnings and:
mvn test -Dtest=ConsulConfigStoreTest#getSimpleConfig
(1) null
(2) io.vertx.core.impl.EventLoopContext@512f413d
(2) io.vertx.core.impl.EventLoopContext@512f413d
@vietj @cescoffier any thoughts on this?
I think the best would be to capture a Context in consul client when it is created and then use runOnContext to use the HttpClient.
I'm not sure it should be done in the consul client or in the config store. For vault I'm doing it in the config store.
Thank you guys. Due to the issues not belongs to vertx-config
, I decided to make all the changes in the parent project
Tests shows some problems with
HttpClient
(see also vert-x3/vertx-consul-client#32):It seems that
ConsulConfigStore
's constructor andget()
method called in differentVertx
contexts. I can confirm this by checkVertx.currentContext()
instance in both points. This patch ruslansennov/vertx-consul-client@319b78c1661083c188b2a346fbdab1784af46cd3 fixes the problem but I'm not sure that this is right way. ~Maybe the problem is insideWebClient
and/orHttpClient
implementations~