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

Java springboot application fails to connect to Valkey Cache using GLIDE #2990

Open
alekhya538 opened this issue Jan 22, 2025 · 16 comments
Open
Assignees
Labels
bug Something isn't working User issue Issue openned by users Users Pain An issue known to cause users pain, generaly open by the user.

Comments

@alekhya538
Copy link

alekhya538 commented Jan 22, 2025

Hello,

We are trying to connect to AWS Valkey Cache (Serverless) from java springboot application (JDK17, springboot-version: 3.2.5).
Trying to use GLIDE as java client to connect to Cache and do Read/Write.

Here is the example code which I got from https://github.com/valkey-io/valkey-glide/blob/main/java/README.md.

private static void readCache() {
        log.info("In readCache");
        String host = "<host>";
        Integer port = 6379;

        GlideClientConfiguration config = GlideClientConfiguration.builder()
                        .address(NodeAddress.builder().host(host).port(port).build())
                        .build();
        log.info("config: " + config);

        try {
            GlideClient client = GlideClient.createClient(config).get();      <---- exception at this line
            log.info("client: " + client);

            log.info("PING: " + client.ping(gs("PING")).get());
            log.info("PING(found you): " + client.ping(gs("found you")).get());

            log.info("SET(cardNumber, 1234): " + client.set(gs("cardNumber"), gs("1234")).get());
            log.info("GET(cardNumber): " + client.get(gs("cardNumber")).get());

        } catch (ExecutionException | InterruptedException e) {
            log.error("Glide example failed with an exception: {}", e);
            e.printStackTrace();
        }
    }

Above code example is failing at line 'GlideClient client = GlideClient.createClient(config).get();'
Getting below error:
java.lang.NoClassDefFoundError: Could not initialize class glide.ffi.resolvers.SocketListenerResolver

Can anyone help how to fix this ?

@barshaul
Copy link
Collaborator

@yipin-chen @Yury-Fridlyand
Can you take a look?

@asafpamzn asafpamzn added Users Pain An issue known to cause users pain, generaly open by the user. Unatriaged user issue Issue open by user and wasn't triaged yet bug Something isn't working labels Jan 22, 2025
@eifrah-aws
Copy link
Contributor

This looks like as if the libglide_rs.so is not being loaded. Could run your application with -verbose:class (I am not sure how to use it inside spring)

@Yury-Fridlyand
Copy link
Collaborator

Hi
How do you add GLIDE dependency in pom/gradle config?

@alekhya538
Copy link
Author

alekhya538 commented Jan 22, 2025

Here are the dependencies added in build.gradle

plugins {
     id "com.google.osdetector" version "1.7.3"
}

dependencies {
    implementation group: 'io.valkey', name: 'valkey-glide', version: '1.+', classifier: osdetector.classifier
    implementation 'io.valkey:valkey-glide:1.2.1'
}

@alekhya538
Copy link
Author

alekhya538 commented Jan 22, 2025

@yipin-chen The log which I added after creating config, prints below:

config: GlideClientConfiguration(reconnectStrategy=null, databaseId=null, subscriptionConfiguration=null, advancedConfiguration=null)

Then this line (GlideClient client = GlideClient.createClient(config).get(); ) immediately throws exception,

`Error
jakarta.servlet.ServletException: Handler dispatch failed: java.lang.NoClassDefFoundError: Could not initialize class 
glide.ffi.resolvers.SocketListenerResolver
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1104)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:564)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:150)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:175)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:150)
at au.com.flybuys.esb.common.logging.ResponseLoggingFilter.doFilterInternal(ResponseLoggingFilter.java:32)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:175)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:150)
at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:108)
at org.springframework.security.web.FilterChainProxy.lambda$doFilterInternal$3(FilterChainProxy.java:231)`

@avifenesh avifenesh added User issue Issue openned by users and removed Unatriaged user issue Issue open by user and wasn't triaged yet labels Jan 22, 2025
@Yury-Fridlyand
Copy link
Collaborator

Yury-Fridlyand commented Jan 23, 2025

Can you post your full list of dependencies please and sprint boot config if possible? I'm curious if something has a conflict with GLIDE's resourses (native lib).

Unfortunately, we cannot reproduce the issue with a sample spring boot app that we have.

@alekhya538
Copy link
Author

alekhya538 commented Jan 23, 2025

Hello,

Here are all the dependencies of my project.

`dependencies {

jaxws 'com.sun.xml.ws:jaxws-tools:4.0.1'

jaxws files("${projectDir}/src/main/java")

annotationProcessor 'org.projectlombok:lombok:1.18.30'
compileOnly 'org.projectlombok:lombok:1.18.30'

implementation 'org.apache.cxf:cxf-spring-boot-starter-jaxws:4.0.3'

implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.security.oauth:spring-security-oauth2:2.5.2.RELEASE'
implementation 'org.springframework.security:spring-security-oauth2-client'

implementation 'com.github.ben-manes.caffeine:caffeine:3.1.8'

implementation 'org.springframework.ws:spring-ws-core:4.0.10'
implementation 'org.springframework.ws:spring-ws-security:4.0.10'

implementation 'au.com.myapp:common-library:0.100.1'
implementation 'au.com.myapp:common-security:0.11.0'
implementation 'com.datadoghq:dd-java-agent:1.22.0'

implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap:4.1.2'
implementation 'io.awspring.cloud:spring-cloud-aws-starter-parameter-store:3.2.0-M1'
implementation 'io.awspring.cloud:spring-cloud-aws-starter-secrets-manager:3.2.0-M1'
implementation 'io.awspring.cloud:spring-cloud-aws-sqs:3.0.1'

//elasticache
//implementation 'software.amazon.awssdk:elasticache:2.30.2'
implementation 'io.lettuce:lettuce-core:6.5.2.RELEASE'
implementation 'io.valkey:valkey-java:5.3.0'
implementation group: 'io.valkey', name: 'valkey-glide', version: '1.+', classifier: osdetector.classifier
implementation 'io.valkey:valkey-glide:1.2.1'
implementation 'org.redisson:redisson:3.43.0'

implementation 'com.amazonaws:aws-java-sdk:1.12.780'
implementation 'software.amazon.awssdk:aws-sdk-java:2.20.22'

implementation 'jakarta.jws:jakarta.jws-api:3.0.0'

implementation 'io.opentracing:opentracing-api:0.33.0'
implementation 'io.opentracing:opentracing-util:0.33.0'

implementation 'io.springfox:springfox-swagger2:3.0.0'
implementation 'org.apache.commons:commons-lang3:3.12.0'

implementation 'com.google.guava:guava:32.1.2-jre'

runtimeOnly 'org.springframework.boot:spring-boot-starter-actuator'
runtimeOnly 'com.sun.xml.ws:jaxws-rt:4.0.1'
implementation 'org.apache.httpcomponents.client5:httpclient5'
runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc:7.0.0.jre8'

runtimeOnly 'net.logstash.logback:logstash-logback-encoder:7.3'

testAnnotationProcessor 'org.projectlombok:lombok:1.18.30'
testCompileOnly 'org.projectlombok:lombok:1.18.30'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.mockito:mockito-junit-jupiter'
testImplementation 'org.springframework.ws:spring-ws-test'
testImplementation 'io.rest-assured:rest-assured:5.3.0'

testImplementation 'com.github.tomakehurst:wiremock-standalone:3.0.1'
testImplementation 'au.com.myapp:common-library:0.100.1:tests'
testImplementation 'org.apache.commons:commons-collections4:4.4'

testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testRuntimeOnly 'com.h2database:h2:2.2.220'

implementation 'org.bouncycastle:bcprov-jdk15on:1.60'
implementation 'com.google.guava:guava:33.2.1-jre'

}`

@alekhya538
Copy link
Author

alekhya538 commented Jan 23, 2025

I also noticed that I get below exception, the very first time I call the api after server restart.

`Handler dispatch failed: java.lang.UnsatisfiedLinkError: /tmp/nativeutils5539865577097/libglide_rs.so: Error loading shared library libgcc_s.so.1: No such file or directory (needed by /tmp/nativeutils5539865577097/libglide_rs.so)`

From second time onwards, it gives below exception.

`java.lang.NoClassDefFoundError: Could not initialize class glide.ffi.resolvers.SocketListenerResolver`

@Yury-Fridlyand
Copy link
Collaborator

Oh, that's very interesting. Could you verify please that you have libgcc_s on your machine?
Which OS is that? What is the GLIBC version (ldd --version)?

Thanks, that info could be very helpful!

Those are dependencies of GLIDE native components:

$ ldd target/release/libglide_rs.so
        linux-vdso.so.1 (0x00007ffed25f3000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007efc8978a000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007efc896a1000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007efc8948f000)
        /lib64/ld-linux-x86-64.so.2 (0x00007efc89c4f000)
$ ldd ../../libnetty_transport_native_epoll_x86_64.so
        linux-vdso.so.1 (0x00007ffecdff6000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f2ce3103000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f2ce30fe000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2ce2bee000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f2ce3114000)

@alekhya538
Copy link
Author

Thanks Yury. I have macOS Sequoia 15.0.

How do I check if I have libgcc_s ?

When I try ldd --version, I get zsh: command not found: ldd.

@Yury-Fridlyand
Copy link
Collaborator

I called a colleague with a mac to help there.
Do you have an mac with an intel CPU or apple silicon (M1 or so)?

@tjzhang-BQ
Copy link
Collaborator

tjzhang-BQ commented Jan 24, 2025

@alekhya538 ldd isn't typically installed on macOS, if you installed gcc through homebrew, you can try:
sudo find $(brew --prefix) -name "libgcc_s*" to find libgcc_s, upon finding the path to libgcc_s you can run otool -L <path> to inspect the shared libraries and verify its version and dependencies

if homebrew wasn't involved I believe you can still try to locate the file in the GCC library directory by using the find command like find <lib directory path> -name "libgcc_s*"

@alekhya538
Copy link
Author

@Yury-Fridlyand I have Apple M3.

@avifenesh
Copy link
Collaborator

avifenesh commented Jan 24, 2025

@alekhya538
To my understanding, the cause is the library isn’t in any directory that Java expects libraries to be in.
Presumably since new macOS is using are not using .so anymore but .dylib.
Please verify gcc exists by running gcc --verison, if it doesn't, run brew install gcc.
If GCC didn't exist, and you installed, it might solve the issue.
New versions of macOS are no longer using .so but dylib so the issue might persist.
If it does, it's easily solved by creating a symlink.
Run ls -l /opt/homebrew/opt/gcc/lib/gcc/current/ and locate the libgcc_s.1.1.dylib -> sudo mkdir -p /usr/local/lib -> sudo ln -sf /opt/homebrew/opt/gcc/lib/gcc/current/libgcc_s.1.1.dylib /usr/local/lib/libgcc_s.so.1

Then in you application.properties add java.library.path=/usr/local/lib:/opt/homebrew/opt/gcc/lib/gcc/current or run the app using java -Djava.library.path=/usr/local/lib:/opt/homebrew/opt/gcc/lib/gcc/current -jar your-app.jar.

Which IDE do you use? If IntelliJ you can also go to Run -> Edit Configurations, and add to VM options -Djava.library.path=/usr/local/lib:/opt/homebrew/opt/gcc/lib/gcc/current.

Please let me know if it helped!

In the next release we will validate we release both for macOS 14 and both newer.

@Yury-Fridlyand
Copy link
Collaborator

As I found, gcc exists on macos OOTB. Is that possible that macos 15 doesn't have libgcc_s?

@avifenesh
Copy link
Collaborator

As I found, gcc exists on macos OOTB. Is that possible that macos 15 doesn't have libgcc_s?

I checked on mine, and it was under brew. I didn't install it directly, but i assume it came with one of the packages.
So i guess if it's under brew it means it was installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working User issue Issue openned by users Users Pain An issue known to cause users pain, generaly open by the user.
Projects
Status: No status
Development

No branches or pull requests

8 participants