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

Scripts don't try EVAL after EVALSHA fails [DATAREDIS-356] #932

Closed
spring-projects-issues opened this issue Nov 24, 2014 · 4 comments
Closed
Assignees

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Nov 24, 2014

Amit Ron opened DATAREDIS-356 and commented

(noticed after upgrading from 1.3.1 to 1.4.1, then adding a new script)

If I run a script that hasn't been run on the Redis before, Spring executes EVALSHA first, which fails with error "NOSCRIPT", throwing an exception.

In version 1.3.1 (expected): the exception is caught and EVAL is executed instead

In version 1.4.1 (bug): the exception caused by NOSCRIPT reaches my code, instead of being properly caught and handled


Affects: 1.4.1 (Evans SR1)

Referenced from: pull request #115

Backported to: 1.4.2 (Evans SR2)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 24, 2014

Thomas Darimont commented

Hello Amit,

thanks for reporting this. Which Redis driver are you using?
In org.springframework.data.redis.core.script.DefaultScriptExecutor.eval(RedisConnection, RedisScript<T>, ReturnType, int, byte[][], RedisSerializer<T>) we first try to eval the sha1 of the given Script and if that fails we fall back with an eval(...).

Could you provide us with the stacktrace and a small test case that reproduces this issue?

Cheers,
Thomas

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 24, 2014

Thomas Darimont commented

I just gave this a spin and the following works as expected:

DefaultRedisScript<String> script = new DefaultRedisScript<String>();
script.setScriptText("return 'BUBU" + System.currentTimeMillis() + "'");
script.setResultType(String.class);
		
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(redisTemplate);
assertEquals("BUBU", scriptExecutor.execute(script, null).substring(0,4));

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 25, 2014

Amit Ron commented

Driver: Jedis 2.5.1

Exception:

org.springframework.dao.InvalidDataAccessApiUsageException: NOSCRIPT No matching script. Please use EVAL.; nested exception is redis.clients.jedis.exceptions.JedisDataException: NOSCRIPT No matching script. Please use EVAL.
        at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:44)
        at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:36)
        at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:37)
        at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:37)
        at org.springframework.data.redis.connection.jedis.JedisConnection.convertJedisAccessException(JedisConnection.java:195)
        at org.springframework.data.redis.connection.jedis.JedisConnection.evalSha(JedisConnection.java:2814)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.springframework.data.redis.core.CloseSuppressingInvocationHandler.invoke(CloseSuppressingInvocationHandler.java:57)
        at com.sun.proxy.$Proxy77.evalSha(Unknown Source)
        at org.springframework.data.redis.core.script.DefaultScriptExecutor.eval(DefaultScriptExecutor.java:81)
        at org.springframework.data.redis.core.script.DefaultScriptExecutor$1.doInRedis(DefaultScriptExecutor.java:71)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:190)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:152)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:140)
        at org.springframework.data.redis.core.script.DefaultScriptExecutor.execute(DefaultScriptExecutor.java:60)
        at org.springframework.data.redis.core.script.DefaultScriptExecutor.execute(DefaultScriptExecutor.java:54)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:288)

(...)

Caused by: redis.clients.jedis.exceptions.JedisDataException: NOSCRIPT No matching script. Please use EVAL.
        at redis.clients.jedis.Protocol.processError(Protocol.java:113)
        at redis.clients.jedis.Protocol.process(Protocol.java:131)
        at redis.clients.jedis.Protocol.read(Protocol.java:200)
        at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:285)
        at redis.clients.jedis.Connection.getOne(Connection.java:267)
        at redis.clients.jedis.BinaryJedis.evalsha(BinaryJedis.java:3302)
        at org.springframework.data.redis.connection.jedis.JedisConnection.evalSha(JedisConnection.java:2811)
        ... 59 more

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 26, 2014

Thomas Darimont commented

I could reproduce this bug now, I prepared a fix as a PR

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

Successfully merging a pull request may close this issue.

None yet
2 participants