[GH-ISSUE #15] Memory leak while embedding C libxlsxwriter in Ruby #12

Closed
opened 2026-05-05 11:24:28 -06:00 by gitea-mirror · 6 comments
Owner

Originally created by @eroncastro on GitHub (Dec 1, 2015).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/15

Originally assigned to: @jmcnamara on GitHub.

Hi! First of all, thank you for this wonderful lib.

I am trying to use it within my Ruby on Rails project by calling it using FFI. But, when deploying it to my production server, I am getting memory leaks that generate files which names contains some parts of the content of my .xlsx, not in the directory it was called, by in the root directory of my application.
Yesterday, I also got the problem:
[ERROR][packager.c:62]: Error opening zip file for xlsx
[ERROR][workbook.c:1108]: Memory allocation failed.

Do I have to grant writing permission recursively to the directories preceding the directory where the file is being generated? I there a way you would recommend me to simulate my production environment in order to effectively test the embedded lib?

Thanks in advance!

Eron

Originally created by @eroncastro on GitHub (Dec 1, 2015). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/15 Originally assigned to: @jmcnamara on GitHub. Hi! First of all, thank you for this wonderful lib. I am trying to use it within my Ruby on Rails project by calling it using FFI. But, when deploying it to my production server, I am getting memory leaks that generate files which names contains some parts of the content of my .xlsx, not in the directory it was called, by in the root directory of my application. Yesterday, I also got the problem: [ERROR][packager.c:62]: Error opening zip file for xlsx [ERROR][workbook.c:1108]: Memory allocation failed. Do I have to grant writing permission recursively to the directories preceding the directory where the file is being generated? I there a way you would recommend me to simulate my production environment in order to effectively test the embedded lib? Thanks in advance! Eron
gitea-mirror 2026-05-05 11:24:28 -06:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@jmcnamara commented on GitHub (Dec 1, 2015):

But, when deploying it to my production server, I am getting memory leaks that generate files which names contains some parts of the content of my .xlsx, not in the directory it was called, by in the root directory of my application.

The libxlsxwriter lib creates some temporary files that are zipped/assembled into a xlsx file. It is possible that if the application fails that these temp files are left behind. Typically they are xml files.

This shouldn't be causing a memory leak though.

Yesterday, I also got the problem:

[ERROR][packager.c:62]: Error opening zip file for xlsx
[ERROR][workbook.c:1108]: Memory allocation failed.

This is a misleading error. It is caused by not having sufficient write permission to create the output file. See the explanation in Issue #12.

Do I have to grant writing permission recursively to the directories preceding the directory where the file is being generated?

Possibly. You, or your app, should be able to do something like this without getting an error:

touch /path/to/output/dir/some_new_file.xlsx

I there a way you would recommend me to simulate my production environment in order to effectively test the embedded lib?

I don't have any sure fire suggestions. Debugging write permission in a web app can be tricky.

By the way, there is a Ruby port of the original Perl module that libxlsxwriter is ported from: https://github.com/cxn03651/write_xlsx

<!-- gh-comment-id:161024304 --> @jmcnamara commented on GitHub (Dec 1, 2015): > But, when deploying it to my production server, I am getting memory leaks that generate files which names contains some parts of the content of my .xlsx, not in the directory it was called, by in the root directory of my application. The libxlsxwriter lib creates some temporary files that are zipped/assembled into a xlsx file. It is possible that if the application fails that these temp files are left behind. Typically they are xml files. This shouldn't be causing a memory leak though. > Yesterday, I also got the problem: > > ``` > [ERROR][packager.c:62]: Error opening zip file for xlsx > [ERROR][workbook.c:1108]: Memory allocation failed. > ``` This is a misleading error. It is caused by not having sufficient write permission to create the output file. See the explanation in Issue #12. > Do I have to grant writing permission recursively to the directories preceding the directory where the file is being generated? Possibly. You, or your app, should be able to do something like this without getting an error: ``` touch /path/to/output/dir/some_new_file.xlsx ``` > I there a way you would recommend me to simulate my production environment in order to effectively test the embedded lib? I don't have any sure fire suggestions. Debugging write permission in a web app can be tricky. By the way, there is a Ruby port of the original Perl module that libxlsxwriter is ported from: https://github.com/cxn03651/write_xlsx
Author
Owner

@eroncastro commented on GitHub (Dec 1, 2015):

Thank you for answering.

I already use write_xlsx gem. The problem with it is that it consumes too much memory when exporting a large number of rows (~ 1MM), which makes my app to stop the process in order not to fall.
When I used your solution embedded with my Rails app in constant memory mode, it only consume 2% of my machine RAM and took only 30 seconds to generate my .xlsx file. I'm going to try once again and I'll report you any other issues!

Thank you again!

<!-- gh-comment-id:161028478 --> @eroncastro commented on GitHub (Dec 1, 2015): Thank you for answering. I already use write_xlsx gem. The problem with it is that it consumes too much memory when exporting a large number of rows (~ 1MM), which makes my app to stop the process in order not to fall. When I used your solution embedded with my Rails app in constant memory mode, it only consume 2% of my machine RAM and took only 30 seconds to generate my .xlsx file. I'm going to try once again and I'll report you any other issues! Thank you again!
Author
Owner

@jmcnamara commented on GitHub (Dec 1, 2015):

I already use write_xlsx gem. The problem with it is that it consumes too much memory when exporting a large number of rows (~ 1MM), which makes my app to stop the process in order not to fall.

I didn't realise that the Ruby port hadn't ported the constant_memory/optimization mode. It was in the original Perl module and is in my Python and Lua versions as well.

<!-- gh-comment-id:161032156 --> @jmcnamara commented on GitHub (Dec 1, 2015): > I already use write_xlsx gem. The problem with it is that it consumes too much memory when exporting a large number of rows (~ 1MM), which makes my app to stop the process in order not to fall. I didn't realise that the Ruby port hadn't ported the constant_memory/optimization mode. It was in the original Perl module and is in my Python and Lua versions as well.
Author
Owner

@eroncastro commented on GitHub (Dec 1, 2015):

I used strace command to attach it to the process. The error I get is the following:

open("/var/www/app/public/exports/ff/c3/8e/ffc38ef077171f690eb01cfe8792845b/test.xlsx", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 EACCES (Permission denied)
write(2, "[ERROR][packager.c:62]: Error op"..., 56) = 56
write(2, "[ERROR][workbook.c:1108]: Memory"..., 52) = 52
write(1, "=> 1\n", 5)

I just did not realise yet what is causing this.

<!-- gh-comment-id:161074954 --> @eroncastro commented on GitHub (Dec 1, 2015): I used strace command to attach it to the process. The error I get is the following: open("/var/www/app/public/exports/ff/c3/8e/ffc38ef077171f690eb01cfe8792845b/test.xlsx", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 EACCES (Permission denied) write(2, "[ERROR][packager.c:62]: Error op"..., 56) = 56 write(2, "[ERROR][workbook.c:1108]: Memory"..., 52) = 52 write(1, "=> 1\n", 5) I just did not realise yet what is causing this.
Author
Owner

@jmcnamara commented on GitHub (Dec 8, 2015):

Closing this issue because it looks more like a permissions issue than a libxlsxwriter issue.

Note, the current HEAD version gives a clearer error message in this condition:

    $ make examples       
    $ ./examples/hello          

    $ chmod -w hello_world.xlsx 
    $ ./examples/hello          
    [ERROR] Error creating 'hello_world.xlsx': Permission denied
<!-- gh-comment-id:162858555 --> @jmcnamara commented on GitHub (Dec 8, 2015): Closing this issue because it looks more like a permissions issue than a libxlsxwriter issue. Note, the current HEAD version gives a clearer error message in this condition: ``` bash $ make examples $ ./examples/hello $ chmod -w hello_world.xlsx $ ./examples/hello [ERROR] Error creating 'hello_world.xlsx': Permission denied ```
Author
Owner

@AlfonsoUceda commented on GitHub (Jun 1, 2016):

@eroncastro do you have your wrapper open sourced?

@jmcnamara sorry if this bothers you

<!-- gh-comment-id:223102146 --> @AlfonsoUceda commented on GitHub (Jun 1, 2016): @eroncastro do you have your wrapper open sourced? @jmcnamara sorry if this bothers you
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#12
No description provided.