Skip to content
This repository was archived by the owner on May 4, 2018. It is now read-only.

Commit 38fc6ad

Browse files
committed
unix: unref fs event watcher
Watchers were being ref-counted twice which wasn't harmful in itself but stopped uv_unref() from working like you'd expect it to.
1 parent 43e3ac5 commit 38fc6ad

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

src/unix/kqueue.c

+2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ static void uv__fs_event_start(uv_fs_event_t* handle) {
4343
handle->fd,
4444
EV_LIBUV_KQUEUE_HACK);
4545
ev_io_start(handle->loop->ev, &handle->event_watcher);
46+
ev_unref(handle->loop->ev);
4647
}
4748

4849

4950
static void uv__fs_event_stop(uv_fs_event_t* handle) {
51+
ev_ref(handle->loop->ev);
5052
ev_io_stop(handle->loop->ev, &handle->event_watcher);
5153
}
5254

src/unix/linux.c

+2
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,14 @@ int uv_fs_event_init(uv_loop_t* loop,
283283

284284
ev_io_init(&handle->read_watcher, uv__inotify_read, fd, EV_READ);
285285
ev_io_start(loop->ev, &handle->read_watcher);
286+
ev_unref(loop->ev);
286287

287288
return 0;
288289
}
289290

290291

291292
void uv__fs_event_destroy(uv_fs_event_t* handle) {
293+
ev_ref(handle->loop->ev);
292294
ev_io_stop(handle->loop->ev, &handle->read_watcher);
293295
uv__close(handle->fd);
294296
handle->fd = -1;

src/unix/sunos.c

+2
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,14 @@ int uv_fs_event_init(uv_loop_t* loop,
166166

167167
ev_io_init(&handle->event_watcher, uv__fs_event_read, portfd, EV_READ);
168168
ev_io_start(loop->ev, &handle->event_watcher);
169+
ev_unref(loop->ev);
169170

170171
return 0;
171172
}
172173

173174

174175
void uv__fs_event_destroy(uv_fs_event_t* handle) {
176+
ev_ref(handle->loop->ev);
175177
ev_io_stop(handle->loop->ev, &handle->event_watcher);
176178
uv__close(handle->fd);
177179
handle->fd = -1;

test/test-fs-event.c

+19-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static void timer_cb(uv_timer_t* handle, int status) {
282282
ASSERT(status == 0);
283283

284284
r = uv_fs_event_init(handle->loop, &fs_event, ".", fs_event_fail, 0);
285-
ASSERT(r != -1);
285+
ASSERT(r == 0);
286286

287287
uv_close((uv_handle_t*)&fs_event, close_cb);
288288
uv_close((uv_handle_t*)handle, close_cb);
@@ -308,3 +308,21 @@ TEST_IMPL(fs_event_immediate_close) {
308308

309309
return 0;
310310
}
311+
312+
313+
TEST_IMPL(fs_event_unref) {
314+
uv_loop_t* loop;
315+
int r;
316+
317+
loop = uv_default_loop();
318+
319+
r = uv_fs_event_init(loop, &fs_event, ".", fs_event_fail, 0);
320+
ASSERT(r == 0);
321+
322+
uv_unref(loop);
323+
324+
r = uv_run(loop);
325+
ASSERT(r == 0);
326+
327+
return 0;
328+
}

test/test-list.h

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ TEST_DECLARE (fs_event_watch_file)
112112
TEST_DECLARE (fs_event_watch_file_current_dir)
113113
TEST_DECLARE (fs_event_no_callback_on_close)
114114
TEST_DECLARE (fs_event_immediate_close)
115+
TEST_DECLARE (fs_event_unref)
115116
TEST_DECLARE (fs_readdir_empty_dir)
116117
TEST_DECLARE (fs_readdir_file)
117118
TEST_DECLARE (fs_open_dir)
@@ -268,6 +269,7 @@ TASK_LIST_START
268269
TEST_ENTRY (fs_event_watch_file_current_dir)
269270
TEST_ENTRY (fs_event_no_callback_on_close)
270271
TEST_ENTRY (fs_event_immediate_close)
272+
TEST_ENTRY (fs_event_unref)
271273
TEST_ENTRY (fs_readdir_empty_dir)
272274
TEST_ENTRY (fs_readdir_file)
273275
TEST_ENTRY (fs_open_dir)

0 commit comments

Comments
 (0)