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

luv_fs: fix gc of string during a fs.write #223

Merged
merged 1 commit into from May 16, 2012

Conversation

philips
Copy link
Contributor

@philips philips commented May 15, 2012

In virgo we hit a bug that only revealed itself when we were writing out to a
file over NFS. This is likely because the NFS write out took a relatively long
time and revealed a race. Example corrupted text file:

#
ch0002
tests/tmp/0002.chk
OK
»A¿7—A
ch0003
tests/tmp/0003.chk
OK
1337118370

Notice that the fifth line is garbage. That is because the string was getting
GC'd before it was written to disk. So, we need to ref the string so this
doesn't happen just as we ref the callback function.

In virgo we hit a bug that only revealed itself when we were writing out to a
file over NFS. This is likely because the NFS write out took a relatively long
time and revealed a race. Example corrupted text file:

    #
    ch0002
    tests/tmp/0002.chk
    OK
    »A¿7—A
    ch0003
    tests/tmp/0003.chk
    OK
    1337118370

Notice that the fifth line is garbage. That is because the string was getting
GC'd before it was written to disk. So, we need to ref the string so this
doesn't happen just as we ref the callback function.
@@ -258,7 +279,10 @@ int luv_fs_write(lua_State* L) {
off_t offset = luaL_checkint(L, 2);
size_t length;
void* chunk = (void*)luaL_checklstring(L, 3, &length);
uv_fs_t* req = luv_fs_store_callback(L, 4);
luv_fs_ref_t* ref = luv_fs_ref_alloc(L);
luv_fs_ref_string(ref, 3);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the unref someplace else in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hrm, weird, I wrote the code but must have forgotten that second git add. I will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philips
Copy link
Contributor Author

philips commented May 16, 2012

@rphillips fwiw, the windows build failure on virgo-bb is because of this: https://virgo-bb.k1k.me/builders/virgo-windows2008_x64/builds/842/steps/integration%20tests/logs/stdio

@rphillips
Copy link
Member

lgtm, +1

philips added a commit that referenced this pull request May 16, 2012
luv_fs: fix gc of string during a fs.write
@philips philips merged commit 7aa587c into master May 16, 2012
@rphillips rphillips deleted the fix-string-gc-in-fs-write branch November 18, 2014 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants