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

Race conditions in in-memory pass template #24

Open
rwngallego opened this issue Dec 20, 2024 · 2 comments
Open

Race conditions in in-memory pass template #24

rwngallego opened this issue Dec 20, 2024 · 2 comments

Comments

@rwngallego
Copy link
Contributor

rwngallego commented Dec 20, 2024

We've noticed that certain race conditions could occur when we use this library to process a high volume of passes using an in-memory pass template. Although I intended to submit this issue with an associated PR to resolve the problem, I realized this might require more work than expected, so I'm submitting the issue in advance and potentially creating a PR later.

This is one of the race conditions we've found when loading assets from a URL:

==================
WARNING: DATA RACE
Write at 0x00c000472000 by goroutine 10:
  runtime.mapaccess2_faststr()
      ../1.22.8/go/src/runtime/map_faststr.go:108 +0x42c
  github.com/alvinbaena/passkit.(*InMemoryPassTemplate).AddFileFromURL()
      ../go/pkg/mod/github.com/alvinbaena/passkit@v0.0.0-20231118075341-79567105cd75/templates.go:140 +0x88

There's another one when signing a pass:

github.com/alvinbaena/passkit.(*memorySigner).CreateSignedAndZippedPassArchive(0xc00047c2d0?, 0x1871450?, {0x186aa18?, 0xc003746030?}, 0xe?)
/go/pkg/mod/github.com/alvinbaena/passkit@v0.0.0-20231118075341-79567105cd75/mem_signer.go:28 +0x157
github.com/alvinbaena/passkit.(*memorySigner).CreateSignedAndZippedPersonalizedPassArchive(0x23ae720, 0xc005147008, 0x0, {0x186aa18?, 0xc003746030?}, 0xc0038fe320)
/go/pkg/mod/github.com/alvinbaena/passkit@v0.0.0-20231118075341-79567105cd75/mem_signer.go:115
github.com/alvinbaena/passkit.(*memorySigner).makeFilesCopy(...)
goroutine 217 [running]:
fatal error: concurrent map iteration and map write

We solved those problems using an external mutex. Still, we could make the in-memory template concurrency-safe by using a mutex to protect the InMemoryPassTemplate.files internal map.

@rwngallego rwngallego changed the title In-memory template race conditions Race conditions in In-memory pass template Dec 20, 2024
@rwngallego rwngallego changed the title Race conditions in In-memory pass template Race conditions in in-memory pass template Dec 20, 2024
@alvinbaena
Copy link
Owner

Thank you for reporting this issue.

You're welcome to submit a PR :)

@alvinbaena
Copy link
Owner

I've created a branch for thread safety. Could you test if it works and report back?

Thanks.

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

No branches or pull requests

2 participants