-
Notifications
You must be signed in to change notification settings - Fork 845
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
redis from mruby #1152
Merged
Merged
redis from mruby #1152
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
8d65fa9
add mruby redis feature
i110 033a9a1
Merge branch 'i110/mruby-consistent-fiber-handling' into i110/mruby-r…
i110 c41ad6d
tweak for mruby-redis
i110 4275123
fix mruby-redis gc problem
i110 da6c09f
Merge branch 'master' into i110/mruby-redis
i110 9c6034c
call ensure_connected for all commands
i110 b100dd5
fix redis reply allocation problem
i110 a9bfb96
Merge branch 'i110/mruby-consistent-fiber-handling' into i110/mruby-r…
i110 01b0526
Merge branch 'i110/mruby-consistent-fiber-handling' into i110/mruby-r…
i110 4ebc107
Merge branch 'i110/mruby-consistent-fiber-handling' into i110/mruby-r…
i110 f1d3f2b
fix redis reader memory issue
i110 5351d1a
tweak redis
i110 c0eeda0
raise CommandError when redis command failed
i110 2e33a36
define redis methods
i110 b803182
remove redis reader
i110 92226db
add error code and message in redis command callback
i110 64bc23d
add redis streaming command
i110 c904a00
fix mruby redis bugs
i110 f486184
add redis mruby tests
i110 fc7e026
install redis-server on travis
i110 b506c88
Merge branch 'master' into i110/mruby-redis
i110 f594f7c
- refactor mruby x redis
i110 4714f02
add connected? method to H2O::Redis
i110 87b1b31
Merge branch 'master' into i110/mruby-redis
i110 0199663
fix mruby redis gc issue
i110 6094301
add :db and :password option to H2O::Redis
i110 fdc79ee
remove unnecessary nil check
i110 ad1dee8
Merge remote-tracking branch 'origin/master' into i110/mruby-redis
i110 adfa1c3
Merge branch 'master' into i110/mruby-redis
i110 117a679
fix redis example client
i110 347699e
mruby-redis subscribe
i110 a5a295b
mruby-redis connect and command timeout
i110 65fea24
reformat
i110 e10def2
remove redis's fancy ascii art from test output
i110 3bdcdba
fix mruby redis test issue
i110 67f4459
set mruby redis default timeout to 5 secs
i110 57d3f86
fix mruby redis timeout destroying issue
i110 80b8950
fix mruby-redis command timeout issue
i110 66a627d
Merge branch 'master' into i110/mruby-redis
i110 70132d8
fix memory leak of mruby-redis
i110 6c8facb
Merge branch 'master' into i110/mruby-redis
i110 15c4ef7
tweak
i110 64b6077
remove redis error argument
i110 ee3cbc0
Merge branch 'master' into i110/mruby-redis
i110 3ead0da
refactor redis
i110 a872f9d
Merge branch 'i110/asan-symbols' into i110/mruby-redis
i110 c3d0f85
remove unnecessary NULL checks
i110 05fe2a6
rename close_connection to close_and_detach_connection, and move call…
i110 0e7f9be
rename h2o_redis_conn_t to h2o_redis_client_t
i110 dcad6e5
remove unnecessary enum definition
i110 9460efb
re-format changes
i110 3c997a9
fix heap-use-after-free problem
i110 ee0494c
Merge branch 'master' into i110/mruby-redis
kazuho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix mruby-redis gc problem
- Loading branch information
commit 4275123054a5abde5a86d2a63bdad3198c9254f5
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,65 +59,45 @@ redisReplyObjectFunctions reader_object_functions = { | |
reader_free_object | ||
}; | ||
|
||
static void on_gc_dispose_redis(mrb_state *mrb, void *_conn) | ||
{ | ||
struct st_h2o_mruby_redis_conn_t *conn = _conn; | ||
if (conn == NULL) return; | ||
|
||
h2o_redis_free(&conn->super); | ||
conn->refs.redis = mrb_nil_value(); | ||
} | ||
|
||
static void on_gc_dispose_command(mrb_state *mrb, void *_ctx) | ||
{ | ||
struct st_h2o_mruby_redis_command_context_t *ctx = _ctx; | ||
if (ctx == NULL) return; | ||
|
||
ctx->refs.command = mrb_nil_value(); | ||
} | ||
|
||
const static struct mrb_data_type redis_type = {"redis", on_gc_dispose_redis}; | ||
const static struct mrb_data_type command_type = {"redis_command", on_gc_dispose_command}; | ||
|
||
static mrb_value create_downstream_closed_exception(mrb_state *mrb) | ||
{ | ||
return mrb_exc_new_str_lit(mrb, E_RUNTIME_ERROR, "downstream HTTP closed"); | ||
} | ||
|
||
static void attach_receiver(struct st_h2o_mruby_redis_command_context_t *ctx, mrb_value receiver) | ||
{ | ||
assert(mrb_nil_p(ctx->receiver)); | ||
ctx->receiver = receiver; | ||
mrb_gc_register(ctx->conn->ctx->shared->mrb, receiver); | ||
} | ||
|
||
static mrb_value detach_receiver(struct st_h2o_mruby_redis_command_context_t *ctx) | ||
static mrb_value detach_receiver(struct st_h2o_mruby_redis_command_context_t *ctx, int protect) | ||
{ | ||
mrb_value ret = ctx->receiver; | ||
assert(!mrb_nil_p(ret)); | ||
ctx->receiver = mrb_nil_value(); | ||
mrb_gc_unregister(ctx->conn->ctx->shared->mrb, ret); | ||
mrb_gc_protect(ctx->conn->ctx->shared->mrb, ret); | ||
if (protect) mrb_gc_protect(ctx->conn->ctx->shared->mrb, ret); | ||
return ret; | ||
} | ||
|
||
static void on_command_dispose(void *_ctx) | ||
static void on_gc_dispose_redis(mrb_state *mrb, void *_conn) | ||
{ | ||
struct st_h2o_mruby_redis_command_context_t *ctx = _ctx; | ||
struct st_h2o_mruby_redis_conn_t *conn = _conn; | ||
if (conn == NULL) return; | ||
|
||
/* TODO: is this necessary? */ | ||
if (!mrb_nil_p(ctx->refs.command)) | ||
DATA_PTR(ctx->refs.command) = NULL; | ||
h2o_redis_free(&conn->super); | ||
conn->refs.redis = mrb_nil_value(); | ||
} | ||
|
||
/* notify the app, if it is waiting to hear from us */ | ||
if (!mrb_nil_p(ctx->receiver)) { | ||
mrb_state *mrb = ctx->conn->ctx->shared->mrb; | ||
int gc_arena = mrb_gc_arena_save(mrb); | ||
h2o_mruby_run_fiber(ctx->conn->ctx, detach_receiver(ctx), create_downstream_closed_exception(mrb), NULL); | ||
mrb_gc_arena_restore(mrb, gc_arena); | ||
static void on_gc_dispose_command(mrb_state *mrb, void *_ctx) | ||
{ | ||
struct st_h2o_mruby_redis_command_context_t *ctx = _ctx; | ||
if (ctx == NULL) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed at c3d0f85 |
||
if (! mrb_nil_p(ctx->receiver)) { | ||
detach_receiver(ctx, 0); | ||
} | ||
free(ctx); | ||
} | ||
|
||
const static struct mrb_data_type redis_type = {"redis", on_gc_dispose_redis}; | ||
const static struct mrb_data_type command_type = {"redis_command", on_gc_dispose_command}; | ||
|
||
static redisReader *create_reader(h2o_redis_conn_t *_conn) | ||
{ | ||
struct st_h2o_mruby_redis_conn_t *conn = (void *)_conn; | ||
|
@@ -187,7 +167,7 @@ static void on_redis_command(void *_reply, void *_ctx) | |
} | ||
} else { | ||
int gc_arena = mrb_gc_arena_save(mrb); | ||
h2o_mruby_run_fiber(ctx->conn->ctx, detach_receiver(ctx), reply, NULL); | ||
h2o_mruby_run_fiber(ctx->conn->ctx, detach_receiver(ctx, 1), reply, NULL); | ||
mrb_gc_arena_restore(mrb, gc_arena); | ||
} | ||
} | ||
|
@@ -199,7 +179,6 @@ static mrb_value call_method(mrb_state *mrb, mrb_value self) | |
|
||
/* allocate context and initialize */ | ||
struct st_h2o_mruby_redis_command_context_t *command_ctx = h2o_mem_alloc(sizeof(*command_ctx)); | ||
// FIXME: who and when free this? | ||
memset(command_ctx, 0, sizeof(*command_ctx)); | ||
command_ctx->conn = conn; | ||
command_ctx->receiver = mrb_nil_value(); | ||
|
@@ -212,17 +191,26 @@ static mrb_value call_method(mrb_state *mrb, mrb_value self) | |
|
||
const char **argv = h2o_mem_alloc(command_len * sizeof(char *)); | ||
size_t *argvlen = h2o_mem_alloc(command_len * sizeof(size_t)); | ||
|
||
int gc_arena = mrb_gc_arena_save(mrb); | ||
|
||
for (i = 0; i != command_len; ++i) { | ||
int gc_arena = mrb_gc_arena_save(mrb); | ||
mrb_value s = mrb_obj_as_string(mrb, command_args[i]); | ||
argv[i] = mrb_str_to_cstr(mrb, s); | ||
argvlen[i] = mrb_string_value_len(mrb, s); | ||
mrb_gc_arena_restore(mrb, gc_arena); | ||
if (mrb_symbol_p(command_args[i])) { | ||
mrb_int len; | ||
argv[i] = mrb_sym2name_len(mrb, mrb_symbol(command_args[i]), &len); | ||
argvlen[i] = len; | ||
} else { | ||
mrb_value s = mrb_obj_as_string(mrb, command_args[i]); | ||
argv[i] = mrb_string_value_cstr(mrb, &s); | ||
argvlen[i] = mrb_string_value_len(mrb, s); | ||
} | ||
} | ||
|
||
/* send command to redis */ | ||
h2o_redis_command_argv(&conn->super, on_redis_command, command_ctx, (int)command_len, argv, argvlen); | ||
|
||
mrb_gc_arena_restore(mrb, gc_arena); | ||
|
||
free(argv); | ||
free(argvlen); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any chance that
conn
becomes NULL? Unless there's such case, this early return is redundant with the potential of hiding a bug.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed at c3d0f85