Skip to content

Sometimes registerFont() does not work correctly in multiple processes(implemented by cluster) #2019

@PA-LuffyYu

Description

@PA-LuffyYu

Issue:
Sometimes the text can be rendered correctly but sometimes it seems using another default font(same always), it works on one process but doesn't work on another process because I'm using cluster. Since there is a license for the font, I can't upload it here. And I think it should not be relevant to the font as sometimes it really works. It is not happening every time.

Note: The important is that it works fine if fork one process only!!! And it worked well on Canvas 1.6.11 as well before upgraded to 2.9.1

Code:
let cluster = require('cluster');
if(cluster.isPrimary) {
for (let i = 0; i < 8; i++) {
cluster.fork();
}
} else {
const {createCanvas, registerFont} = require('canvas');
const font_path = '/data/fonts/NaiveBold.ttf';
let font_name = 'NaiveBold';
registerFont(font_path, {family: font_name});
let canvas = createCanvas(300, 300);
let ctx = canvas.getContext('2d');
ctx.textAlign = 'left';
ctx.textBaseline = 'middle';
ctx.fillStyle = '#000000;
ctx.font = '20px ' + font_name;
ctx.fillText('This is a test text.', 0, 0);
// Try to save the text into a file to see the issue
// And from here it will start a web server by express
}

Text images generated:
Correct font used:
correct-font
Incorrect font used(always same font):
default-font

Environment:
Nodejs 16.14.0 on Ubontu
Canvas 2.9.1
Fontconfig 2.13.1
Freetype 2.10.4
Cairo 1.16.0
Pango 1.46.0

Are there any ideas? Thank you in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions