@@ -286,15 +286,22 @@ void lock_release(RedisSock *redis_sock, redis_session_lock_status *lock_status
286286 upload_lock_release_script (redis_sock TSRMLS_CC );
287287 cmd_len = REDIS_SPPRINTF (& cmd , "EVALSHA" , "sdss" , REDIS_G (lock_release_lua_script_hash ), strlen (REDIS_G (lock_release_lua_script_hash )), 1 , lock_status -> lock_key .c , lock_status -> lock_key .len , lock_status -> lock_secret .c , lock_status -> lock_secret .len );
288288
289- redis_sock_write (redis_sock , cmd , cmd_len TSRMLS_CC );
290- response = redis_sock_read (redis_sock , & response_len TSRMLS_CC );
289+ if (redis_sock_write (redis_sock , cmd , cmd_len TSRMLS_CC )) {
290+ response = redis_sock_read (redis_sock , & response_len TSRMLS_CC );
291+ } else {
292+ php_error_docref (0 TSRMLS_CC , E_WARNING , "Unable to release session lock (socket write failed)" );
293+ }
291294
292295 // in case of redis script cache has been flushed
293296 if (response == NULL ) {
294297 REDIS_G (lock_release_lua_script_uploaded ) = 0 ;
295- upload_lock_release_script (redis_sock TSRMLS_CC );
296- redis_sock_write (redis_sock , cmd , cmd_len TSRMLS_CC );
297- response = redis_sock_read (redis_sock , & response_len TSRMLS_CC );
298+ int upload_successful = upload_lock_release_script (redis_sock TSRMLS_CC );
299+
300+ if (upload_successful && redis_sock_write (redis_sock , cmd , cmd_len TSRMLS_CC )) {
301+ response = redis_sock_read (redis_sock , & response_len TSRMLS_CC );
302+ } else {
303+ php_error_docref (0 TSRMLS_CC , E_WARNING , "Unable to release session lock (socket write failed)" );
304+ }
298305 lock_status -> is_locked = 0 ;
299306 }
300307
@@ -308,28 +315,38 @@ void lock_release(RedisSock *redis_sock, redis_session_lock_status *lock_status
308315 smart_string_free (& lock_status -> lock_secret );
309316}
310317
311- void upload_lock_release_script (RedisSock * redis_sock TSRMLS_DC )
318+ int upload_lock_release_script (RedisSock * redis_sock TSRMLS_DC )
312319{
313320 if (REDIS_G (lock_release_lua_script_uploaded )) return ;
314321
315322 char * cmd , * response , * release_script ;
316323 int response_len , cmd_len ;
324+ int upload_result = 0 ;
317325 release_script = "if redis.call(\"get\",KEYS[1]) == ARGV[1] then return redis.call(\"del\",KEYS[1]) else return 0 end" ;
318326
319327 cmd_len = REDIS_SPPRINTF (& cmd , "SCRIPT" , "ss" , "LOAD" , strlen ("LOAD" ), release_script , strlen (release_script ));
320328
321- redis_sock_write (redis_sock , cmd , cmd_len TSRMLS_CC );
322- response = redis_sock_read (redis_sock , & response_len TSRMLS_CC );
329+ if (redis_sock_write (redis_sock , cmd , cmd_len TSRMLS_CC )) {
330+ response = redis_sock_read (redis_sock , & response_len TSRMLS_CC );
331+
332+ if (response == NULL ) {
333+ php_error_docref (0 TSRMLS_CC , E_WARNING , "Unable to upload LUA script for releasing session lock (SCRIPT LOAD failed)" );
334+ }
335+ } else {
336+ php_error_docref (0 TSRMLS_CC , E_WARNING , "Unable to upload LUA script for releasing session lock (socket write failed)" );
337+ }
323338
324339 if (response != NULL ) {
325340 memset (REDIS_G (lock_release_lua_script_hash ), 0 , 41 );
326341 strncpy (REDIS_G (lock_release_lua_script_hash ), response , strlen (response ));
327342
328343 REDIS_G (lock_release_lua_script_uploaded ) = 1 ;
344+ upload_result = 1 ;
329345 efree (response );
330346 }
331347
332348 efree (cmd );
349+ return upload_result ;
333350}
334351
335352void calculate_lock_secret (redis_session_lock_status * lock_status )
0 commit comments