Skip to content

cookie jar updates should be atomic #4914

Closed
@vapier

Description

@vapier

I did this

# Create a dummy cookie jar larger than 4KiB.
$ printf '%s\tFALSE\t/\tTRUE\t2147483647\to\tfoo=bar\n' {0..200}.example.com > x

# Run curl reading & writing that cookie jar.
$ strace -e'!signal' curl https://google.com --cookie x --cookie-jar x
...
openat(AT_FDCWD, "x", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
write(4, "# Netscape HTTP Cookie File\n# ht"..., 4096) = 4096
write(4, "e.com\tFALSE\t/\tTRUE\t2147483647\to\t"..., 4096) = 4096
write(4, "LSE\t/\tTRUE\t2147483647\to\tfoo=bar\n"..., 1884) = 1884
close(4)                                = 0
...

I expected the following

other processes accessing the cookie jar should be able to rely on the file being coherent/complete. as it stands, the cookie jar is unreliable with more than one user at a time.

seems like it wouldn't be too difficult to create a tempfile using the name as a base, write to that, then do a single atomic rename.

curl/libcurl version

curl 7.66.0 (x86_64-pc-linux-gnu) libcurl/7.66.0 OpenSSL/1.1.1d zlib/1.2.11 nghttp2/1.39.2

operating system

Linux vapier 5.3.1 #1 SMP PREEMPT Fri Sep 27 00:26:44 EDT 2019 x86_64 AMD FX(tm)-4350 Quad-Core Processor AuthenticAMD GNU/Linux

Activity

bagder

bagder commented on Feb 12, 2020

@bagder
Member

It should indeed be possible to create the file with a temp name and then rename it. I would propose we do it by appending a suffix to the actual name.

jay

jay commented on Feb 12, 2020

@jay
Member

We could use what Mozilla Firefox uses which iirc? is .partfile or .part

added a commit that references this issue on Feb 14, 2020
082d291
added a commit that references this issue on Feb 16, 2020
ead1e24
self-assigned this
on Feb 17, 2020
locked as resolved and limited conversation to collaborators on May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @vapier@bagder@jay

    Issue actions

      cookie jar updates should be atomic · Issue #4914 · curl/curl