Nima on native-image - second request blocked forever
See original GitHub issueOS | win11 |
JDK | GraalVM CE 23.0.0-dev (build 19+36-jvmci-23.0-b01) |
Helidon | 4.0.0-alpha2 |
The second request will be blocking when using Helidon Nima native image.
Main
public class Main {
public static void main(String[] args) {
// 启动完毕后退出 主要用来查看启动耗时
// System.setProperty("exit.on.started", "!");
// SE 下需要在运行入口处初始化 logging
LogConfig.configureRuntime();
configureJackson();
var server = WebServer.builder()
.socket("h1", (sb, rb) -> {
// sb.port(8080); // overrides the config from app.properties
var routing = HttpRouting.builder()
.update(Main::configureRouting)
.build();
rb.addRouting(routing);
})
.start();
}
static ObjectMapper JSON;
static void configureJackson() {
JSON = ObjectMapperCustomFn.createDefault().apply(new ObjectMapper());
}
static void configureRouting(HttpRouting.Builder routing) {
// noinspection unchecked
routing.register("/info", InfoRoute::new);
}
}
Routing
public class InfoRoute implements HttpService {
@Override
public void routing(HttpRules rules) {
rules.get("", this::getInfo);
}
void getInfo(ServerRequest req,
ServerResponse res) {
var info = SystemInfo.create();
res.headers().contentType(HttpMediaType.APPLICATION_JSON);
res.send(info);
}
}
Jackson media support
public class JacksonSupportProvider implements MediaSupportProvider {
private static final System.Logger LOGGER = System.getLogger(JacksonSupportProvider.class.getName());
<T> boolean checkSupported(GenericType<T> type,
Headers requestHeaders,
WritableHeaders<?> responseHeaders) {
if (responseHeaders != null
&& responseHeaders.contentType().filter(v -> v.test(APPLICATION_JSON)).isPresent()) {
return true;
}
return requestHeaders != null && requestHeaders.acceptedTypes().contains(APPLICATION_JSON);
}
@Override
public <T> WriterResponse<T> writer(GenericType<T> type,
WritableHeaders<?> requestHeaders) {
return writer(type, requestHeaders, null);
}
@Override
public <T> WriterResponse<T> writer(GenericType<T> type,
Headers requestHeaders,
WritableHeaders<?> responseHeaders) {
LOGGER.log(TRACE, " writer for type=" + type.getTypeName());
if (checkSupported(type, requestHeaders, responseHeaders)) {
//noinspection unchecked
return new WriterResponse<>(COMPATIBLE, () -> (EntityWriter<T>) JacksonEntityWriter.INSTANCE);
}
return WriterResponse.unsupported();
}
static class JacksonEntityWriter<T> implements EntityWriter<T> {
private static final JacksonEntityWriter<?> INSTANCE = new JacksonEntityWriter<>();
@Override
public void write(GenericType<T> type,
T object,
OutputStream outputStream,
Headers requestHeaders,
WritableHeaders<?> responseHeaders) {
try {
Main.JSON.writeValue(outputStream, object);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void write(GenericType<T> type,
T object,
OutputStream outputStream,
WritableHeaders<?> headers) {
write(type, object, outputStream, headers, null);
}
}
}
Issue Analytics
- State:
- Created a year ago
- Comments:11 (9 by maintainers)
Top Results From Across the Web
Backlog - GitHub
Nima on native-image - second request blocked forever #5273 opened by lost22git 4.x. Version 4.x bug. Something isn't working. Níma Helidon Níma
Read more >Help-blocking IP addresses forever - Community Central
IP addresses can change through VPN, so blocking one won't help much though. But you can contact Fandom Staff to request an IP...
Read more >AirHacks.FM podcast
Lightweight JavaONE session, quarkus native image is a fraction of JVM size, the "compile time boot", performing optimizations at build and not at...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ha! its intermittent, but I can reproduce it
Native-image issue reported to GraalVM project oracle/graal/issues/5540