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

Pdfium is not thread safe #1275

Closed
cypres opened this issue Apr 2, 2019 · 3 comments
Closed

Pdfium is not thread safe #1275

cypres opened this issue Apr 2, 2019 · 3 comments
Labels

Comments

@cypres
Copy link

cypres commented Apr 2, 2019

How do you get around the lack of thread safety in Pdfium, combined with the general promise that libvips is thread safe?

Pdfium's mailing lists are quite clear that they are not thread safe;
https://groups.google.com/forum/#!msg/pdfium/kyIdh_J4csg/K1LvfPiHDwAJ
https://groups.google.com/forum/#!topic/pdfium/HeZSsM_KEUk

@jcupitt
Copy link
Member

jcupitt commented Apr 2, 2019

Hello, libvips puts a lock around PDFium calls so it'll never try to process the same document with more than one thread. This seems to work, in the limited testing I've done.

From your links it looks like we might need to prevent parallel access to different docs as well.

Unfortunately the PDFium build system has changed enough since we added PDFium load to break everything :( It'll need a few days work to get it functioning again.

@cypres
Copy link
Author

cypres commented Apr 2, 2019

Thank you very much for the swift reply, I was looking for a mutex lock or something but didn't find it (I guess I was looking in the wrong place).

We're calling PDFium from Go, and I wondered if it was possible to reduce lock contention without going to multi process.
Currently using this third-party binary distribution of PDFium; https://github.com/bblanchon/pdfium-binaries

@jcupitt
Copy link
Member

jcupitt commented Apr 2, 2019

The lock is in the vips_linecache() call in vips_foreign_load_pdf_load(). It ensures calls into vips_foreign_load_pdf_generate() are single-threaded.

That binary PDFium distribution looks interesting. The last time I looked at PDFium itself, they'd broken library builds completely -- I guess they were concentrating on building as a component of chrome. Hopefully that's fixed now.

@jcupitt jcupitt closed this as completed Apr 11, 2019
jcupitt added a commit that referenced this issue Aug 8, 2019
We used to lock within documents, ie. we did not allow two threads to
work on the same file.

However pdfium is not threadsafe in any way, and this is not supported,
see:

	https://groups.google.com/forum/#!msg/pdfium/kyIdh_J4csg/K1LvfPiHDwAJ

This patch adds locks around pdfium calls.

see:

	#1380
	#1275
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants