kstyrc / embedded-redis

Redis embedded server for Java integration testing
840 stars 368 forks source link

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

Open ptahchiev opened 9 years ago

ptahchiev commented 9 years ago
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 commented 9 years ago

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

aesteve commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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

looser990 commented 9 years ago

As my build is failing on Jenkins (still need to check if it is not https://github.com/kstyrc/embedded-redis/issues/49) I have to ask when do you plan next release with logs? Keep up the good work!

bijanfahimi commented 8 years ago

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 commented 8 years ago

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

altfatterz commented 8 years ago

get the same running on snap-ci

UnspeakableHorror commented 8 years ago

Same problem running in Circle CI.

UnspeakableHorror commented 8 years ago

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

altfatterz commented 8 years ago

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

alexnaspo commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

Any progress here?

Lasantha1984 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

^ 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 commented 8 years ago

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

gmingsoft04 commented 8 years ago

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 commented 8 years ago

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

gmingsoft04 commented 8 years ago

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 commented 8 years ago

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

mohsinkerai commented 7 years ago

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

huberchrigu commented 7 years ago

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 commented 7 years ago

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

ducquoc commented 7 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

redisServer.stop() doesn't stop on OSX

nikhilGitrepo commented 6 years ago

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 commented 5 years ago

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 commented 5 years ago

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

kvzn commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

For me it helped to boot my Win10.

ashok2ashok commented 4 years ago

Resolved the issue to print the log of redis process when there is an error in the PR (merged): https://github.com/ozimov/embedded-redis/pull/10

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

tomparkpro commented 3 years ago

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 commented 3 years ago

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

djassimo commented 3 years ago

Just change port of redis server in config yml ;)

ChicoMetal commented 3 years ago

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 commented 2 years ago

For me, the server was already running as well

LaoYueHanNi commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

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

hxing-Do commented 1 year ago

"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)

Tschis commented 7 months ago

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