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.

Nima on native-image - second request blocked forever

See original GitHub issue
OS 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.

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:open
  • Created a year ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
danielkeccommented, Nov 3, 2022

Ha! its intermittent, but I can reproduce it

0reactions
danielkeccommented, Nov 30, 2022

Native-image issue reported to GraalVM project oracle/graal/issues/5540

Read more comments on GitHub >

github_iconTop 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 >

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