-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native image does not inherit system time zone #5016
Comments
@dmlloyd is this something you have seen before? It sounds like a GraalVM bug, not a Quarkus one. |
No, I have never seen this. I agree this looks like a GraalVM bug. I wonder if it doesn't load the zone database by default to save space. |
Is there any workaround except of explicit specifying time zone every time it is needed? |
I can't reproduce this. I get the right timezone. I'm on Graal Also, can you paste the exact command you use to generate the native image? |
Tried on |
Hello, @jaikiran I'm building native image using maven with docker on Windows 10, running it on Oracle Linux 7 or even Fedora 30. To reproduce:
Docker command is:
|
Stupid question but would the timezone be fixed at build time?
…On Thu, Oct 31, 2019 at 4:09 PM sgerr ***@***.***> wrote:
Hello, @jaikiran <https://github.com/jaikiran>
I'm building native image using maven with docker on Windows 10, running
it on Oracle Linux 7 or even Fedora 30. To reproduce:
1. Create project
mvn io.quarkus:quarkus-maven-plugin:0.27.0:create
-DprojectGroupId=com.sgerr -DprojectArtifactId=tztest
-Dextensions="undertow" -Dpath=tz
1. Create class Starter, use code snippet above.
2. Build native image
mvnw package -Pnative -Dquarkus.native.container-build=true
Docker command is:
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] docker run -v C:\work\sandbox\SandboxProjects\tztest\target\tztest-1.0-SNAPSHOT-native-image-source-jar:/project:z --rm quay.io/quarkus/ubi-quarkus-native-image:19.2.1 -J-Dsu
n.nio.ch.maxUpdateArraySize=100 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Dio.ne
tty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=1 --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -jar tztest-1.0-SNAPSHOT-runner.jar -J-Djava.util.
concurrent.ForkJoinPool.common.parallelism=1 -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:-AddAllCharsets -H:EnableURLProtocols=http -H:-JNI -H:-UseServiceLoaderFeature -H:+StackTrace tztest-1.0-SNAPSHOT-runner
1. Copy and run it on Linux.
# date +%z && ./tztest -Dquarkus.http.port=9999
+0300
--- default time zone id is: GMT
2019-10-31 15:04:57,611 INFO [io.quarkus] (main) tztest 1.0-SNAPSHOT (running on Quarkus 0.27.0) started in 0.016s. Listening on: http://0.0.0.0:9999
2019-10-31 15:04:57,611 INFO [io.quarkus] (main) Profile prod activated.
2019-10-31 15:04:57,611 INFO [io.quarkus] (main) Installed features: [cdi, resteasy, servlet]
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#5016?email_source=notifications&email_token=AAJYOBMRTBIBDBKFOP4WLI3QRLYJNA5CNFSM4JGU4C32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECYEAFI#issuecomment-548421653>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJYOBNMXOM2SPSJGFTUN5DQRLYJNANCNFSM4JGU4C3Q>
.
|
I'm looking at the source code and it looks like this: @AutomaticFeature
final class TimeZoneFeature implements Feature {
static class Options {
@Option(help = "When true, all time zones will be pre-initialized in the image.")//
public static final HostedOptionKey<Boolean> IncludeAllTimeZones = new HostedOptionKey<>(false);
}
@Override
public void afterRegistration(AfterRegistrationAccess access) {
TimeZone defaultZone = TimeZone.getDefault();
String[] supportedZoneIDs = Options.IncludeAllTimeZones.getValue() ? TimeZone.getAvailableIDs() : new String[]{"GMT", "UTC", defaultZone.getID()};
Map<String, TimeZone> supportedZones = Arrays.stream(supportedZoneIDs)
.map(TimeZone::getTimeZone)
.collect(toMap(TimeZone::getID, tz -> tz, (tz1, tz2) -> tz1));
ImageSingletons.add(TimeZoneSupport.class, new TimeZoneSupport(supportedZones, defaultZone));
}
} So it looks to me like it's only including, by default, GMT, UTC, and whatever the build host's time zone is. So if the run host has a different time zone, you won't get it and it'll fall back to UTC. This should be verifiable by building a native image with a different value set for the Setting |
Hello, @dmlloyd Thank you for ypur reply. Please clarify, how to add -H:+IncludeAllTimeZones switch when maven build? |
Oh, yes. Including in pom properties
will do that. Command now is:
But still no effect:
Is it because Windows build? |
I just rebuild project on Fedora 30 (maven, opendjk 1.8, docker).
The same result:
Build host's time zone is neither GMT no UTC. |
It seems that the default time zone is not reset by GraalVM at native image start, so the time zone captured at build is retained. To fix it, there would have to be some startup hook which causes redetection of the default zone. Furthermore there's a bug in that if you set the default time zone to The class with the substitutions references an internal (secret) GraalVM bug ID |
Unfortunatelly, it does not. At build time zone was neither GMT no UTC too. So, no workaround on that except to specify time zone explicitly at start time or invoke |
Did you not say that you were building in a docker container? Are you setting the time zone env var in docker? |
No. I'm using standard maven build procedure as I mentioned above:
|
I believe docker does not inherit the time zone from the host by default. See https://forums.docker.com/t/synchronize-timezone-from-host-to-container/39116/2 |
May be. But it does not matter because the point of our interest is the TZ of host machine at runtime. |
@sgerr what @dmlloyd is saying essentially is that if you do Due to the fact that you are using docker to build the binary, you don't see that behavior because Docker (seemingly) doesn't use the hosts default TZ. |
@geoand, yes. But is it the behaviour you expected? Of course -- not. You are expecting to get host machine time zone at runtime. Moreover in some cases, for example storing timeseries to DB, you do not want to think about time zones at all because Hibernate is clever enought to do this work for you behind the scenes. |
@sgerr so yes, of course the behavior is not expected. What we are trying to do however is set the scene for what the actual problem can be and what is peripheral to the discussion. |
@geoand yes, sure. Meanwhile we can use quarkus in JVM mode where it works as expected. Thank you. |
Thanks! |
Related to #1842 |
I've raised a graal PR oracle/graal#1819 to see if we can have timezone support enhanced to allow more fine grained control on how users or Quarkus can configure the available timezones in native-image. |
Can someone confirm that this is still an issue? |
I confirm too, I have the bug here: quarkiverse/quarkus-univocity-parsers@5321516 the timezone is different between my non-native test phase and the native test phase. I think the "-H:+IncludeAllTimeZones" isn't take in account |
@zakkak do you know if this is still an issue? |
This doesn't look like an issue any more: import java.time.ZoneId;
public class Reproducer {
public static void main(String[] args) {
System.out.println("--- default time zone id is: " + ZoneId.systemDefault());
}
}
|
Closing this. Please comment if you are still seeing the issue. |
Native image does ignore system time zone, assumes GMT instead. Code snippet to verify:
Output (no matter system timezone is):
--- default time zone id is: GMT
The text was updated successfully, but these errors were encountered: