Skip to content
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

Exception: AtomicBuffer is not correctly aligned #122

Closed
appreciated opened this issue May 6, 2024 · 6 comments
Closed

Exception: AtomicBuffer is not correctly aligned #122

appreciated opened this issue May 6, 2024 · 6 comments

Comments

@appreciated
Copy link

appreciated commented May 6, 2024

We are hitting this issue on every startup.

I think this might be related with us using a x86 JVM with Java 17.

Stacktrace

ERROR StatusConsoleListener Could not create plugin of type class pl.tkowalcz.tjahzi.log4j2.LokiAppender for element Loki: java.lang.IllegalStateException: AtomicBuffer is not correctly aligned: addressOffset=12 is not divisible by 8
 java.lang.IllegalStateException: AtomicBuffer is not correctly aligned: addressOffset=12 is not divisible by 8
	at org.agrona.concurrent.UnsafeBuffer.verifyAlignment(UnsafeBuffer.java:388)
	at org.agrona.concurrent.errors.DistinctErrorLog.<init>(DistinctErrorLog.java:124)
	at org.agrona.concurrent.errors.DistinctErrorLog.<init>(DistinctErrorLog.java:112)
	at pl.tkowalcz.tjahzi.stats.StandardMonitoringModule.<init>(StandardMonitoringModule.java:33)
	at pl.tkowalcz.tjahzi.log4j2.LokiAppenderBuilder.build(LokiAppenderBuilder.java:125)
	at pl.tkowalcz.tjahzi.log4j2.LokiAppenderBuilder.build(LokiAppenderBuilder.java:30)
	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:124)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1162)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1083)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1075)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:679)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:264)
	at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:227)
	at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:183)
	at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:69)
	at d.p.o.core.utils.LokiAppenderUtils.initLokiAppender(LokiAppenderUtils.java:72)
	at d.p.o.core.utils.LoggingUtils.configureLogger(LoggingUtils.java:68)
	at d.p.o.localRunner.Start.configureLogger(Start.java:113)
	at d.p.o.localRunner.Start.main(Start.java:35)
ERROR StatusConsoleListener Unable to invoke factory method in class pl.tkowalcz.tjahzi.log4j2.LokiAppender for element Loki: java.lang.IllegalStateException: No factory method found for class pl.tkowalcz.tjahzi.log4j2.LokiAppender
 java.lang.IllegalStateException: No factory method found for class pl.tkowalcz.tjahzi.log4j2.LokiAppender
	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:268)
	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:140)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1162)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1083)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1075)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:679)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:264)
	at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:227)
	at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:183)
	at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:69)
	at d.p.o.core.utils.LokiAppenderUtils.initLokiAppender(LokiAppenderUtils.java:72)
	at d.p.o.core.utils.LoggingUtils.configureLogger(LoggingUtils.java:68)
	at d.p.o.localRunner.Start.configureLogger(Start.java:113)
	at d.p.o.localRunner.Start.main(Start.java:35)

Debugger Screenshots

StandardMonitoringModule

grafik

UnsafeBuffer

grafik
grafik

@tkowalcz
Copy link
Owner

tkowalcz commented May 6, 2024

Can you tell me which exactly java version are you using? I'll try to reproduce it on some VM in the evening (after work).

@appreciated
Copy link
Author

@appreciated
Copy link
Author

Here the same Debugger values with a x64 JVM:

Debugger Screenshot

UnsafeBuffer

grafik

@appreciated
Copy link
Author

appreciated commented May 6, 2024

You should be able to fix this issue by replacing the attribute StandardMonitoringModule.ERROR_LOG_CAPACITY with the following code:

int ERROR_LOG_CAPACITY = UNSAFE.arrayBaseOffset(byte[].class) * 64;

This would result on:

  • 64-Bit Systems in the current value of 1024
  • 32-Bit systems in 768
    These sizes values should work both the UnsafeBuffer.

But I'm not sure if the lower value contradicts with other actual requirements you have with the UnsafeBuffer.
Another, more regression safe solution may be to use a size that that is divisible by 12 and 16 f.e. 1152

@appreciated
Copy link
Author

Fixed by upgrading to new Version:

<dependency>
    <groupId>pl.tkowalcz.tjahzi</groupId>
    <artifactId>log4j2-appender</artifactId>
    <version>0.9.32</version>
</dependency>

@tkowalcz
Copy link
Owner

tkowalcz commented May 6, 2024

Ha! Didn't think of that :) I know I fixed similar error but thought this is yet another x86 issue. Glad you worked it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants