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

"Can't start redis server. Check logs for details" - which logs???? #51

Open
ptahchiev opened this issue May 24, 2015 · 51 comments
Open

Comments

@ptahchiev
Copy link

Caused by: java.lang.RuntimeException: Can't start redis server. Check logs for details.
    at redis.embedded.AbstractRedisInstance.awaitRedisServerReady(AbstractRedisInstance.java:61)
    at redis.embedded.AbstractRedisInstance.start(AbstractRedisInstance.java:39)
    at redis.embedded.RedisServer.start(RedisServer.java:9)
    at com.nemesis.platform.config.PlatformCoreSessionConfig$RedisServerBean.afterPropertiesSet(PlatformCoreSessionConfig.java:82)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:116)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
@kstyrc
Copy link
Owner

kstyrc commented May 27, 2015

In the upcoming release I plan to expose redis logs to file, which you can inspect for issues.

@aesteve
Copy link

aesteve commented Jun 3, 2015

I got the exact same error with both 0.5 and 0.6. Windows 7 64 bits.

If it's happening to you (dear reader) and you have no idea how to debug this until logs are indeed added to the application (thanks for your work btw) you can just do the following.

Use your favorite IDE and create a very simple reproducer :

    public static void main(String... args) throws Exception {
        RedisServer server = new RedisServer(6379);
        server.start();
    }

Then in your favorite IDE, put a breakpoint here and debug the main method in your IDE.

You should be able to read the error message from here. In my case, it was the following :

[9520] 03 Jun 18:12:27.054 # The Windows version of Redis allocates a memory mapped heap for sharing with the forked process used for persistence operations. In order to share this memory, Windows allocates from the system paging file a portion equal to the size of the Redis heap. 

At this time there is insufficient contiguous free space available in the system paging file for this operation (Windows error 0x5AF). 

To work around this you may either increase the size of the system paging file, or decrease the size of the Redis heap with the --maxheap flag. 

Sometimes a reboot will defragment the system paging file sufficiently for this operation to complete successfully. Please see the documentation included with the binary distributions for more details on the --maxheap flag.

Which helped me a lot to diagnose the issue.

Hope this helps someone one day.

(this is actually issue #9 )

@hotienvu
Copy link

I'm also having the same issue. It's running fine on mac os x but when I run this under centos6.6 and redis-2.4 it throws this error

Usage: ./redis-server [/path/to/redis.conf]
       ./redis-server - (read config from stdin)
       ./redis-server --test-memory <megabytes>

java.lang.RuntimeException: Can't start redis server. Check logs for details.
[info]   at redis.embedded.AbstractRedisInstance.awaitRedisServerReady(AbstractRedisInstance.java:61)
[info]   at redis.embedded.AbstractRedisInstance.start(AbstractRedisInstance.java:39)
[info]   at redis.embedded.RedisServer.start(RedisServer.java:9)

I have been spending a lot of time debugging this so a better logging mechanism would be really appreciated

@hotienvu
Copy link

Hey sorry, it was because of the version of redis is too old. After I upgrade redis, everything works fine

@looser990
Copy link

As my build is failing on Jenkins (still need to check if it is not #49) I have to ask when do you plan next release with logs? Keep up the good work!

@bijanfahimi
Copy link

Same here for me, I get java.lang.RuntimeException: Can't start redis server. Check logs for details. when running on Jenkins (Centos 6.6), but tests pass if running locally on Ubuntu 15.

@bijanfahimi
Copy link

Using a redis-server build which was created on a CentOS System solved it for me.

@altfatterz
Copy link

get the same running on snap-ci

@UnspeakableHorror
Copy link

Same problem running in Circle CI.

@UnspeakableHorror
Copy link

Turns out that Circle had it's own Redis instance using the same port. Just changing the port fixed it.

@altfatterz
Copy link

on snap-ci I also started use the provided redis service, so no need to start an embedded one

@alexnaspo
Copy link

I am having the same error on my jenkins build running on Debian 4.8.4-1. Has there been any update here? I cannot install redis on the jenkins machine.

This project is great! thank you!

@phdd
Copy link

phdd commented Feb 11, 2016

In my case, the problem was an already running instance of the Redis server (port already in use). Seems like one application shutdown went wrong and therefore failed to kill it.

@casidiablo
Copy link

Yeah... this sometimes happens. What I do, which seems to work fine, is to start the redis server with a random port. That way, if the CI build fails to stop the redis server there's no problem since the new runs will have a different port. Also allows for safer concurrent builds since there are no conflicts.

@ptahchiev
Copy link
Author

Any progress here?

@Lasantha1984
Copy link

Hi I got the same issue . Simple what I did is just clear the C: disc and remove unnecessary program installed, clear desktop and clear recycle bin and increase the virtual memory . worked fined for me.

@arshadalisoomro
Copy link

Hey there! I was pulling my hairs to resolve :

Caused by: java.lang.RuntimeException: Can't start redis server. Check logs for details.
    at edis.embedded.AbstractRedisInstance.awaitRedisServerReady(AbstractRedisInstance.java:61)
    at redis.embedded.AbstractRedisInstance.start(AbstractRedisInstance.java:39)
    at redis.embedded.RedisServer.start(RedisServer.java:9)

error, finally I saw an instance of redis server is already running in background, So I killed that proccess and Re-rn the App and Yeah the App worked without that error.

@casidiablo
Copy link

^ that. What I usually do, and it might not work for all use cases, is to always start the server with a random port. I can do this because I start/discard servers for every unit tests that needs them.

@gmingsoft04
Copy link

C:\Users\ADMINI~1\AppData\Local\Temp\1469700558020-0\redis-server-2.8.19.exe

@gmingsoft04
Copy link

path error:File executable = RedisExecProvider.defaultProvider().get();
System.out.println("======executable:" + executable.getAbsolutePath());
======executable:C:\Users\ADMINI~1\AppData\Local\Temp\1469700558020-0\redis-server-2.8.19.exe

@gmingsoft04
Copy link

public RedisServer(int port) throws IOException {
super(port);

@gmingsoft04
Copy link

C:\Users\Administrator>F:\it\redis\redis-server-2.8.19.exe
[8468] 28 Jul 18:19:18.622 #
The Windows version of Redis allocates a memory mapped heap for sharing with
the forked process used for persistence operations. In order to share this
memory, Windows allocates from the system paging file a portion equal to the
size of the Redis heap. At this time there is insufficient contiguous free
space available in the system paging file for this operation (Windows error
0x5AF). To work around this you may either increase the size of the system
paging file, or decrease the size of the Redis heap with the --maxheap flag.
Sometimes a reboot will defragment the system paging file sufficiently for
this operation to complete successfully.

Please see the documentation included with the binary distributions for more
details on the --maxheap flag.

Redis can not continue. Exiting.

@gmingsoft04
Copy link

Redis-x64-3.2.100.zip
https://github.com/MSOpenTech/redis/releases

@mohsinkerai
Copy link

Build failing on Ubuntu 12.02, i686 (32 Bit) through Jenkins due to Same issue. Any updates on it?

@huberchrigu
Copy link

The problem lies in the following function awaitRedisServerReady() for me. There the startup input stream of redis is just ignored and parsed for the "ready" line only. But sometimes there is other important information logged into there, like the reason why the startup fails. So I need to debug this function to find out the actual reason. Would be nice if this stream would be logged somewhere and not just ignored.

@mohsinkerai
Copy link

For me it worked after shifting it on 64 Bit Machine.. !!

@ducquoc
Copy link

ducquoc commented Jul 27, 2017

Thank @aesteve and @dalilagauge . On Windows 64-bit it works after setting maxheap.

@Configuration
@Profile("test")
public class EmbeddedRedisServer {

    @Value("${spring.redis.port:6380}")
    private int redisPort;

    private RedisServer redisServer;

    @PostConstruct
    public void startRedis() throws IOException, URISyntaxException {
        //redisPort = org.springframework.util.SocketUtils.findAvailableTcpPort(6380);
        //RedisExecProvider customRedisExec = RedisExecProvider.defaultProvider().override
        //        (OsArchitecture.detect().os(), OsArchitecture.detect().arch(), "redis-server-2.8.19.exe");

        redisServer = RedisServer.builder()
                .port(redisPort)
                //.redisExecProvider(customRedisExec) //com.github.kstyrc (not com.orange.redis-embedded)
                .setting("maxmemory 128M") //maxheap 128M
                .build();
        redisServer.start();
    }

    @PreDestroy
    public void stopRedis() throws InterruptedException {
        if (redisServer != null) {
            redisServer.stop();
        }
    }
}

hope this helps somebody someday,

@vasilesmartup
Copy link

vasilesmartup commented Nov 2, 2017

I am seeing this problem (on Arch Linux) in the outputLine of redisProcess:
[21412] 02 Nov 12:02:10.430 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
If I start embeded redis with maxclients=1024, it works. Maybe it helps someone

@jiallombardo
Copy link

jiallombardo commented Feb 12, 2018

The same issue surfaces when creating a Cluster using sample code in README (with RedisCluster.builder()). However, the work-around of using custom settings, like @ducquoc suggested, doesn't work, since RedisClusterBuilder#buildMaster and RedisClusterBuilder#buildSlaves invoke builder.reset, hence passing configured RedisServerBuilders to RedisClusterBuilder effectively does nothing.

What worked for me was to subclass RedisServerBuilder like so:

class CustomClusterRedisServerBuilder extends RedisServerBuilder {

    @Override
    void reset() {
        def confBuilderField = this.class.superclass.declaredFields.find {it.name == 'redisConfigBuilder'}
        confBuilderField.setAccessible(true)

        def oldConfBuilder = confBuilderField.get(this)

        super.reset()

        confBuilderField.set(this, oldConfBuilder)
    }
}

This is effectively a hack, which only works when you use custom settings, like I did. If you omit resetting entirely, though, you will end up with masters being slaves to other masters (since the configuration object is reused).

and then use it when building a cluster:

RedisCluster.builder()
                .sentinelPorts(redisSentinels) //btw, order counts here, if you set ports after setting replication groups
                .serverPorts(redisHosts) //you will get different ports. Go figure
                .withServerBuilder(new CustomClusterRedisServerBuilder().setting("maxmemory 128").setting("maxheap 128M")) //same goes for settings
                .withSentinelBuilder(RedisSentinel.builder().setting("maxmemory 128").setting("maxheap 128M"))
                .sentinelCount(3)
                .quorumSize(2)
                .replicationGroup("master1", 1)
                .replicationGroup("master2", 1)
                .replicationGroup("master3", 1)
                .build()

Hope that helps somebody. Please note - I use this setup for tests, so this code could theoretically have ramifications if used for other purposes.

@daggerok
Copy link

redisServer.stop() doesn't stop on OSX

@nikhilGitrepo
Copy link

Well in my case I was running embedded redis-server on port 1337 and this port was locked and went into a loop sometime back when I was running my testcases in debug mode. After that I also started spring-boot app which created another server connection on the port 6379. But I failed to terminate the server running on the port 1337. Since then I had been getting the exception when I was trying to execute test cases "Can't start redis server. Check logs for details.", since 1337 was locked. Debugging line-my-line "AbstractRedisInstance" class and "awaitRedisServerReady" method revealed "1337 Already in use" which was never logged at all. Killed this port and re-run testcases, everything was good. Hope this helps

@SumukhDeshpande
Copy link

SumukhDeshpande commented Jan 17, 2019

Hello,

I am using Embedded Redis for running my JUnit Tests. All the tests are passing locally but when I try to run them on a Jenkins Server then they fail with error below (same as mentioned by @looser990) :

Also I am not able to find the root cause. I even tried providing a specific range of random ports which are neither reserved nor used. But it did not help.

Is there anything else which I can try to make sure that I am able to debug on Jenkins instance?

Caused by: java.lang.RuntimeException: Can't start redis server. Check logs for details. at redis.embedded.AbstractRedisInstance.awaitRedisServerReady(AbstractRedisInstance.java:61) at redis.embedded.AbstractRedisInstance.start(AbstractRedisInstance.java:39) at redis.embedded.RedisServer.start(RedisServer.java:9) at com.manulife.it.grs.utility.initialLoad.processor.EmbeddedRedis.startRedis(EmbeddedRedis.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498)

To add one more detail. The Redis version is

0.6

as dependency in my Maven POM.

@vkopichenko
Copy link

See also #77 which suggests that maxmemory is more reliable than maxheap.

@kvzn
Copy link

kvzn commented Nov 5, 2019

I fixed it after tons of trying with the way below, now thank me:):


import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import redis.embedded.RedisServer;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class EmbeddedRedis {

    @Value("${spring.redis.port:6378}")
    private int redisPort;

    private static RedisServer redisServer = null;

    @PostConstruct
    public void startRedis() {
        if (redisServer == null || !redisServer.isActive()) {
            redisServer = new RedisServer(redisPort);
            redisServer.start();
        }
    }

    @PreDestroy
    public void stopRedis() {
        if (redisServer != null) {
            redisServer.stop();
        }
    }
}

@wk-tw
Copy link

wk-tw commented Nov 27, 2019

When you are trying to restart RedisServer for example between RestController test and Service test which are using cache, you are getting this error : "Can't start redis server. Check logs for details."
The thing is, you are not going to kill manually the server between two spring boot tests...

@juliocesarsantos1020
Copy link

Hello people!
Has anyone been able to solve this problem? I'm going through the same.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embededRedis': Invocation of init method failed; nested exception is java.lang.RuntimeException: Can't start redis server. Check logs for details.

Interesting that when the docker is active, redis does not work.
When I disable the docker, it will work again.

@aesteve
Copy link

aesteve commented Jan 6, 2020

Probably conflicting ports.

Check this answer to setup a minimal reproducer, then add a break-point.

When the break point is hit and your application pauses: in your debugger you should be able to inspect the root cause. (as stated above).

Probably docker && embeddedRedis are using the same port. But by using your debugger you should be able to know.

@isrikanth999
Copy link

When you are trying to restart RedisServer for example between RestController test and Service test which are using cache, you are getting this error : "Can't start redis server. Check logs for details."
The thing is, you are not going to kill manually the server between two spring boot tests...

Im facing the same problem. Please let me know if you're able to resolve the issue.

@SamuelWiet
Copy link

For me it helped to boot my Win10.

ashok2ashok pushed a commit to ashok2ashok/embedded-redis that referenced this issue Mar 12, 2020
This resolves the issue: kstyrc#51

While resolving logs at the process level is preferred as specified in the pull-request: kstyrc#113 - this fix takes a much more conservative approach and prints the redis process logs only in case of an error/exception when the server startup pattern is not found. That way we do not need to worry about logs in case of successful redis server starts.
ashok2ashok pushed a commit to ashok2ashok/embedded-redis that referenced this issue Mar 12, 2020
This resolves the issue: kstyrc#51

While resolving logs at the process level is preferred as specified in the pull-request: kstyrc#113 - this fix takes a much more conservative approach and prints the redis process logs only in case of an error/exception when the server startup pattern is not found. That way we do not need to worry about logs in case of successful redis server starts.

Dist updated to trusty to resolves travis jdk8 build issue caused by xenial dist

Removed sudo and curl commands as they are not longer supported.
jpm4j is not longer functional and sudo is deprecated in travis
@ashok2ashok
Copy link

Resolved the issue to print the log of redis process when there is an error in the PR (merged): ozimov#10

You can find this once @robertotru releases the next version - i.e. - 0.7.3+

@tomparkpro
Copy link

I fixed it after tons of trying with the way below, now thank me:):


import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import redis.embedded.RedisServer;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class EmbeddedRedis {

    @Value("${spring.redis.port:6378}")
    private int redisPort;

    private static RedisServer redisServer = null;

    @PostConstruct
    public void startRedis() {
        if (redisServer == null || !redisServer.isActive()) {
            redisServer = new RedisServer(redisPort);
            redisServer.start();
        }
    }

    @PreDestroy
    public void stopRedis() {
        if (redisServer != null) {
            redisServer.stop();
        }
    }
}

this works for me!!

@untaljohanperez
Copy link

Just using a different port worked for me
@ClassRule public static final EmbeddedRedisServer redisServer = new EmbeddedRedisServer(8002+1);

@djassimo
Copy link

Just change port of redis server in config yml ;)

@ChicoMetal
Copy link

ChicoMetal commented Jun 3, 2021

Well, i don't know if any one else hava the same problem, my problem was i didn't configure @activeprofiles("production") on my config reddis, i think this made an interference.
The stranger is at local is succes :/

@Deepikaj10
Copy link

For me, the server was already running as well

@LaoYueHanNi
Copy link

I also encountered this problem. I saw that redis server was still running in the task manager and guessed that the port was occupied, so after modifying the code and testing, I manually called the stop method to close redisserver.

@Cimballi
Copy link

Cimballi commented Jul 7, 2022

It seems we should now be able to see the logs message in the exception, no ? But I see :
Caused by: java.lang.RuntimeException: Can't start redis server. Check logs for details. Redis process log:

@lvvorovi
Copy link

it is 2023, and I still see the same message.

@hxing-Do
Copy link

"main@1" prio=5 tid=0x1 nid=NA runnable
java.lang.Thread.State: RUNNABLE
at java.io.FileInputStream.readBytes(FileInputStream.java:-1)
at java.io.FileInputStream.read(FileInputStream.java:255)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:284)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
- locked <0x89f> (a java.io.BufferedInputStream)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
- locked <0x8a0> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:161)
at java.io.BufferedReader.readLine(BufferedReader.java:324)
at java.io.BufferedReader.readLine(BufferedReader.java:389)
at redis.embedded.AbstractRedisInstance.awaitRedisServerReady(AbstractRedisInstance.java:58)
at redis.embedded.AbstractRedisInstance.start(AbstractRedisInstance.java:39)
- locked <0x859> (a redis.embedded.RedisServer)
at redis.embedded.RedisServer.start(RedisServer.java:9)
at com.yonyou.yms.mariadb.EmbeddedRedisEngine.start(EmbeddedRedisEngine.java:34)

@Tschis
Copy link

Tschis commented Dec 11, 2023

nearing 2024, problem still occurs
in my case, on MacOS and M2
3x colleagues on Linux do not have the issue

Dockerfile is a simple:

FROM gradle:8.5-jdk21 AS builder
ADD . /src
WORKDIR /src
RUN gradle clean build -is

...
<omitted as the build fails on gradle command above>

This is supposed to build our app but the test step of gradle fails due to embedded redis not being able to succeed.
Running gradle clean build locally works just fine, same with running tests through IDEA Intellij.
It only happens during docker build

@Tschis
Copy link

Tschis commented Dec 12, 2023

nearing 2024, problem still occurs in my case, on MacOS and M2 3x colleagues on Linux do not have the issue

Dockerfile is a simple:

FROM gradle:8.5-jdk21 AS builder
ADD . /src
WORKDIR /src
RUN gradle clean build -is

...
<omitted as the build fails on gradle command above>

This is supposed to build our app but the test step of gradle fails due to embedded redis not being able to succeed. Running gradle clean build locally works just fine, same with running tests through IDEA Intellij. It only happens during docker build

I solved this by using --platform=linux/amd64 on my Dockerfile
Also had issues with the gradle:8.5-jdk21-alpine image, and could only make it work with gradle:8.5-jdk21

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