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

Forking vs read_color_table() #25

Closed
melak opened this issue Nov 13, 2017 · 1 comment
Closed

Forking vs read_color_table() #25

melak opened this issue Nov 13, 2017 · 1 comment

Comments

@melak
Copy link
Contributor

melak commented Nov 13, 2017

Consider the following:

use GD::Simple;

for (1..100)
{
    my $pid = fork;

    if(!defined($pid))
    {
        next;
    }

    if($pid == 0)
    {
        GD::Simple->new->bgcolor('transparent');
        exit;
    }
}

This fails more often than not, producing the following output:

unknown color at /usr/local/lib/perl5/site_perl/mach/5.26/GD/Simple.pm line 856, <DATA> line 52.
unknown color at /usr/local/lib/perl5/site_perl/mach/5.26/GD/Simple.pm line 856.
unknown color at /usr/local/lib/perl5/site_perl/mach/5.26/GD/Simple.pm line 856, <DATA> line 55.
unknown color at /usr/local/lib/perl5/site_perl/mach/5.26/GD/Simple.pm line 856.
[...]

With some debugging put in, it becomes reasonably clear that DATA's position is literally all over the place, reading completely random stuff from completely random places in Simple.pm. The gist of this obviously comes down to DATA being a typeglob and all that, in a concurrent scenario like the above, several processes read from it, some will be missing some data, eventually one of them will also make it skip past __END__, and after a short while everything goes bonkers.

I've been playing with a couple of naive ideas for a fix, but the only real solution seems to be not building %COLORS at run-time.

Any other suggestions or observations perhaps before I put in a pull request with a static table?

@melak melak changed the title Forking vs read_color_table() vs read_color_table() Nov 13, 2017
@melak melak changed the title vs read_color_table() Forking vs read_color_table() Nov 13, 2017
@rurban
Copy link
Collaborator

rurban commented Nov 14, 2017

No, sounds good

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