kstyrc / embedded-redis

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

Annoying alert when starting redis embedded. #45

Open gochev opened 9 years ago

gochev commented 9 years ago

When starting redis embedded as part of another applicaiton (spring boot in this case) i am getting each time a very very annoying alert message ( see screenshot for more details ).

And this is happening each time.. I do use solr embedded and elastic search embedded and tomcat and hazelcast but only redis shows this bad confirmation, none of the other asks me do I want to allow incoming connection.. this just looks very bad and basically makes redis unusable since it doesn't look very professional.

screen shot 2015-04-14 at 14 04 27

kstyrc commented 9 years ago

First of all, embedded-redis aim was to be able to run integration tests without external dependencies (like redis server running somewhere).

Whenever you use embedded Tomcat and/or Solr, you actually use some Java code - you stay within the boundaries of a single process. On the other hand, embedded-redis runs redis executable in a separate process from a shell. I guess that your firewall recognizes it as harmful.

Not sure what to think about it. On the one hand, it is outside of the scope of this project, but on the other.. I should look into that..

kstyrc commented 9 years ago

Any more hints on how to reproduce the issue? How do you run it exactly?

gochev commented 9 years ago

I see :( but bad indeed this allow .. I hope doesnt show up on windows machines :(

anyway I answered in the other bug but I am adding the comment here as well :

We have a spring boot application and we import the following configuration that starts the embedded redis.

@Configuration public class PlatformCoreSessionConfig {

@Bean(name = "sessionStrategy")
public HttpSessionStrategy defaultSessionStrategy() {
    final CookieHttpSessionStrategy result = new CookieHttpSessionStrategy();
    result.setCookieName("SESSION");
    return result;
}

@Bean
public static RedisServerBean redisServer() {
    return new RedisServerBean();
}

@Bean(name = { "defaultRedisSessionRepository", "sessionRepository" })
public SessionRepository defaultRedisSessionRepository(JedisConnectionFactory redisCF) throws Exception {
    return new RedisOperationsSessionRepository(redisCF);
}

@Bean
public JedisConnectionFactory connectionFactory(final Environment environment) throws Exception {
    final JedisConnectionFactory jcf = new JedisConnectionFactory();
    jcf.setHostName(environment.getProperty("platform.redis.host", String.class, "localhost"));
    jcf.setPort(environment.getProperty("platform.redis.port", Integer.class, Protocol.DEFAULT_PORT));
    jcf.setPassword(environment.getProperty("platform.redis.password", String.class, ""));
    jcf.afterPropertiesSet();

    return jcf;
}

/**
 * Implements BeanDefinitionRegistryPostProcessor to ensure this Bean
 * is initialized before any other Beans. Specifically, we want to ensure
 * that the Redis Server is started before RedisHttpSessionConfiguration
 * attempts to enable Keyspace notifications.
 */
static class RedisServerBean implements InitializingBean, DisposableBean, BeanDefinitionRegistryPostProcessor {
    private RedisServer redisServer;

    public void afterPropertiesSet() throws Exception {
        redisServer = new RedisServer(Protocol.DEFAULT_PORT);
        redisServer.start();
    }

    public void destroy() throws Exception {
        if (redisServer != null) {
            redisServer.stop();
        }
    }

    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
    }

    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    }
}

}

kstyrc commented 9 years ago

I am a bit worried that if you start RedisServer from within Tomcat context, it can enforce its java policy.. Will try to reproduce this on Linux (unfortunately I have no MacOS to try ;<).

gochev commented 9 years ago

well on linux .. at least it looks everything works as expected :( the two strange things I am noticing are only under mac os x ..

kstyrc commented 9 years ago

I would love to investigate the issue, but it will be hard for me without MacOS. Is there any way to run MacOS on a VM?

gochev commented 9 years ago

You can run MacOS X on VMware workstation for example :) for sure .. however the license says that in order to run it you have to "have mac" I mean it is illigal to run it on a NON mac machine :D however you can do that of course. VirtualBox maybe also support Mac OS X Guests this days but never tried that.. I have used only vmware workstation to run mac os x guest on windows host machine ( http://www.sysprobs.com/vmware-workstation-8-0-8-0-1-unlocker-to-run-mac-os-x-guest-in-windows-7 )

I am using Yosemite the latest up2date 10.10.3 (but I guess 10.10.0 will work the same)

bhowell2 commented 9 years ago

This is due to your firewall. I have to turn mine off when running unit tests (I can't click fast enough to allow it). System Preferences -> Security and Privacy -> (click lock at bottom to make changes, enter password) Click turn off firewall.

Alternatively, you can enable it in the firewall options (hit the plus button if it's not there): screen shot 2015-04-25 at 12 29 00 pm

zyro23 commented 9 years ago

similar problem on windows. i think because the redis server executable is run from a varying temp dir (like c:\users\dummy\appdata\local\temp\1430045057907-0\redis-server-2.8.19.exe), the windows firewall detects it as "new" application every time asking to allow/deny. but even when clicking allow, it seems that is too late, app quits with stacktrace like "no connection...".

gochev commented 9 years ago

@zyro23 yes exactly this is the issue.

The problem is the redis-embedded starts each time from a different folder.. for example : /private/var/folders/81/4b80lf6x533gsbx5wyhvzyg00000gn/T/1430215668163-0/redis-server-2.8.19.app

which means.. that ones I grand it permission to start this permission doesnt stay, instead it asks me again and again and again and what @bhowell2 is saying is undoable ( I mean to add it in the firewall application list)

Is it possible the redis-server to be started from a non randomly generated name folder each time ? this way the firewall issue will not be an issue.

bhowell2 commented 9 years ago

Yeah, sorry, I realized a little after that adding it to the list was not viable as it was random every time. Hopefully disabling your firewall is an option for you until it's fixed!

Edit: Fixed autocorrect!

cleiter commented 9 years ago

To avoid the windows firewall alert it's possible to only bind to localhost (RedisServer.builder().setting("bind 127.0.0.1")...build(). At least that works for me.

kstyrc commented 8 years ago

Hi, will try to make the executable dir to be stable in the next release.

ghost commented 8 years ago

cleiter's solution works on windows. Many thanks!

platinummonkey commented 8 years ago

verified on Mac El Capitan that @cleiter 's solution worked.

comauguste commented 7 years ago

@cleiter 's solution also worked for me on Windows.

Thank you

anirudhjayakumar commented 6 years ago

Is there a similar solution for RedisCluster? I don't see a settings() API for RedisCluster

MichaelSp commented 6 years ago

Doesn't look like it will be fixed for RedisCluster soon... :(

tmack8001 commented 4 years ago

Any plan to release a version that fixes this out of the box?

taylorcressy commented 4 years ago

Was this ever fixed with RedisCluster?