Open glassfox opened 2 years ago
which precise version of Vert.x
can you show the exact code also that leads to that, without it we can only speculate.
Version: vertx-4.3.1
Following code of JacksonFactory:
public class JacksonMysqlFactory extends JacksonFactory {
public static final JacksonFactory INSTANCE = new JacksonFactory();
public static final JacksonCodec CODEC;
static {
JacksonCodec codec;
try {
codec = new MysqlDatabindCodec();
} catch (Throwable ignore) {
ignore.printStackTrace();
// No databind
codec = new JacksonCodec();
}
CODEC = codec;
}
@Override
public JsonCodec codec() {
return CODEC;
}
}
Currently I build JsonObject, suitable for reproducer.
I cannot exactly reproduce the concurrent modification but I do see some odd behavior here:
public class MainVerticle extends AbstractVerticle {
public static void main(String[] args) {
Vertx.clusteredVertx(new VertxOptions())
.compose(vertx -> {
return vertx.deployVerticle(new MainVerticle());
})
.onFailure(err -> {
err.printStackTrace();
System.exit(1);
});
}
@Override
public void start() {
vertx.eventBus()
.<JsonObject>consumer("webrtc.test")
.handler(msg -> {
vertx.setTimer(1L, t -> {
System.out.println(msg.body());
});
});
final JsonObject json = new JsonObject().put("key1", "value1");
vertx.eventBus().send("webrtc.test", json);
json.remove("key1");
}
}
When using a cluster eventbus, because the delivery is lazy, the delivered message will be empty:
{}
While if we're doing single vert.x:
public static void main(String[] args) {
Vertx.vertx().deployVerticle(new MainVerticle())
.onFailure(err -> {
err.printStackTrace();
System.exit(1);
});
}
The message is copied earlier:
{"key1", "value1"}
You will see that io.vertx.core.eventbus.impl.HandlerRegistration#deliverMessageLocally()
copies the message at different times. This is called from sendOrPub()
I agree that the body should not be lazily copied but instead when the message is sent ? so the sender can modify it after sending it.
ConcurrentModificationException has been occurred in JsonObject.encode. Following the inputs: