Sharp fails on resize with zsh: killed - node.js

I have a small node script to resize images for a website:
const sharp = require('sharp')
const fsp = require('fs/promises')
const path = require('path')
const FILES = [
'/home/xx/68/ea/68ea8c14c2b655c50cbc560b9f3a5af620882670.jpeg',
'/home/xx/4e/7f/4e7f94103480d8ff231b17310c598470dc10489c.jpeg',
]
const SIZES = [ 300, 500, 800, 1024, 2048 ]
const FORMATS = [ 'jpeg' ]
const dir = '/home/xx/media/temp/'
async function generatePreviews(pathName, name) {
const image = sharp(pathName)
const metadatas = await image.metadata()
console.log('format:', metadatas.format)
console.log('width:', metadatas.width)
console.log('height:', metadatas.height)
console.log('weight:', await fsp.stat(pathName))
for (const size of SIZES) {
for (const format of FORMATS) {
console.log('start create preview', name, format, size)
try {
await image.clone()
.resize(size, size, {fit: 'inside'})
.toFile(path.join(dir, `preview_${name}_${size}.${format}`))
console.log('Preview created', name, format, size)
} catch (e) {
console.log('An error occured')
console.log(e)
}
}
}
}
async function testPreviews() {
console.log('start generating previews')
for (let i = 0; i < FILES.length; i++) {
await generatePreviews(FILES[i], i)
}
console.log('All previews generated')
}
testPreviews()
It works perfectly on my desktop computer (old i5 760 from 2010), but on my server, it fails almost silently when generating the largest previews for the largest file…
Here is the output on the server:
% node ./src/scripts/test_sharp.js
start generating previews
format: jpeg
width: 683
height: 1024
weight: Stats {
dev: 51713,
mode: 33188,
nlink: 1,
uid: 1001,
gid: 1001,
rdev: 0,
blksize: 4096,
ino: 658937,
size: 473209,
blocks: 928,
atimeMs: 1654021875500.3074,
mtimeMs: 1467568028343.9807,
ctimeMs: 1645954831869.6965,
birthtimeMs: 1645954825541.6052,
atime: 2022-05-31T18:31:15.500Z,
mtime: 2016-07-03T17:47:08.344Z,
ctime: 2022-02-27T09:40:31.870Z,
birthtime: 2022-02-27T09:40:25.542Z
}
start create preview 0 jpeg 300
Preview created 0 jpeg 300
start create preview 0 jpeg 500
Preview created 0 jpeg 500
start create preview 0 jpeg 800
Preview created 0 jpeg 800
start create preview 0 jpeg 1024
Preview created 0 jpeg 1024
start create preview 0 jpeg 2048
Preview created 0 jpeg 2048
format: jpeg
width: 3840
height: 5760
weight: Stats {
dev: 51713,
mode: 33188,
nlink: 1,
uid: 1001,
gid: 1001,
rdev: 0,
blksize: 4096,
ino: 658752,
size: 2272667,
blocks: 4440,
atimeMs: 1654021876468.3223,
mtimeMs: 1468007124640.3523,
ctimeMs: 1645954169924.1448,
birthtimeMs: 1645954151475.8787,
atime: 2022-05-31T18:31:16.468Z,
mtime: 2016-07-08T19:45:24.640Z,
ctime: 2022-02-27T09:29:29.924Z,
birthtime: 2022-02-27T09:29:11.476Z
}
start create preview 1 jpeg 300
Preview created 1 jpeg 300
start create preview 1 jpeg 500
Preview created 1 jpeg 500
start create preview 1 jpeg 800
zsh: killed node ./src/scripts/test_sharp.js
It fails at 800px side preview generation for the largest file (5760 x 3840px).
The catch block doesn't trigger…
Server is a 1 CPU VPS with 1GB of RAM (hosted at gandi.net).
% node --version
v16.15.0
% yarn list --pattern sharp 1 Jun 04:06:40
yarn list v1.22.18
└─ sharp#0.30.6
Done in 1.49s.
Any help would be appreciated :)

Related

Shared memory `shmctl`: Permissions denied

I am trying to use shared memory in a process without using sudo.
My minimal example:
fn main() {
const KEY:i32 = 453845;
const SIZE:usize = 1024*1024;
unsafe {
let shmid = libc::shmget(KEY, SIZE, libc::IPC_CREAT);
dbg!(shmid);
dbg!(*libc::__errno_location());
let mut description: MaybeUninit<libc::shmid_ds> = MaybeUninit::uninit();
let result = libc::shmctl(KEY, libc::IPC_STAT, description.as_mut_ptr());
dbg!(description.assume_init_read());
dbg!(result);
dbg!(*libc::__errno_location());
}
}
produces the output:
[shared-memory-allocator/src/lib.rs:561] shmid = 1015817
[shared-memory-allocator/src/lib.rs:565] description.assume_init_read() = shmid_ds {
shm_perm: ipc_perm {
__key: 0,
uid: 0,
gid: 0,
cuid: 0,
cgid: 0,
mode: 0,
__pad1: 0,
__seq: 0,
__pad2: 0,
__unused1: 0,
__unused2: 0,
},
shm_segsz: 0,
shm_atime: 0,
shm_dtime: 0,
shm_ctime: 0,
shm_cpid: 0,
shm_lpid: 0,
shm_nattch: 0,
__unused4: 0,
__unused5: 0,
}
[shared-memory-allocator/src/lib.rs:566] result = -1
[shared-memory-allocator/src/lib.rs:567] *libc::__errno_location() = 22
Which is to note that it errors with error code 22 e.g. Permission Denied.
This seems like a simple use case, but checking https://linux.die.net/man/2/shmctl and https://linux.die.net/man/2/shmget has no description of permissions. Looking at https://www.ibm.com/docs/en/zos/2.1.0?topic=functions-shmget-get-shared-memory-segment it does note you can pass permission bits.
But if I change it to
let permissions = (libc::S_IRGRP | libc::S_IROTH | libc::S_IRUSR | libc::S_IWGRP | libc::S_IWOTH | libc::S_IWUSR) as i32;
let shmid = libc::shmget(KEY, SIZE, libc::IPC_CREAT | permissions);
The result is shmget now fails:
[shared-memory-allocator/src/lib.rs:562] shmid = -1
[shared-memory-allocator/src/lib.rs:563] *libc::__errno_location() = 13

Link overlap, on target port

I have an issue with link, on target port device, it unusually overlaps the target port.... check my fiddle . I also have attached a screenshot overlap image. Someone have any suggestions? Thanks!
I think JointJS is calculating that your source and target should be considered an obstacle. Adding the excludeEnds option in your fiddle seems to resolve the issue. You can see the option in the following docs.
https://resources.jointjs.com/docs/jointjs/v3.5/joint.html#routers.manhattan
Your code example could be the following:
var link = new joint.dia.Link({
// source: { id: el1.id },
// target: { id: el2.id },
router: { name: 'manhattan', args: { excludeEnds: ['source', 'target'] } },
connector: { name: 'rounded' },
attrs: {
'.connection': {
stroke: 'red',
'stroke-width': 5
},
'.marker-target': {
fill: 'red',
d: 'M 10 0 L 0 5 L 10 10 z'
},
'.marker-source': { /*stroke: '#fe854f',*/ fill: 'red', d: 'M 10 0 L 0 5 L 10 10 z' },
}
});

Using golang to create a new child process with syscall.CLONE_NEWUSER but why at the new usernamespace the uid is nobody?

exe := exec.Command("/proc/self/exe","init")
exe.SysProcAttr = &syscall.SysProcAttr{
Cloneflags: syscall.CLONE_NEWUTS|syscall.CLONE_NEWNS|syscall.CLONE_NEWUSER|syscall.CLONE_NEWPID|syscall.CLONE_NEWIPC|syscall.CLONE_NEWNET,
//mapping the uid and gid I can figure out the mapping rules????
UidMappings: []syscall.SysProcIDMap{
{
ContainerID: 0,
HostID: 1000000,
Size: 65536,
},
},
GidMappings: []syscall.SysProcIDMap{
{
ContainerID: 0,
HostID: 100000,
Size: 65536,
},
},
}
when I run with exe.Start() get the result at terminal is "nobody#xx:/home/xx$" .
I read the code of runc ,likewise,runc use the same way to implement usernamespace's isolation,but set correctly uid with 'root'. what's wrong with me?
There is system info of my new process,getting from another bash.
root#xx:/home/xx# cat /proc/159624/uid_map
0 1000000 65536
root#xx:/home/xx# cat /etc/subuid
xx:100000:65536
os: ubuntu20.04
go version:1.18.3 linux/amd64

Using IIPImage server with openseadragon

I have the IIPImage server running and I am trying to display a deepzoom image but fail
This is how I am doing it :
var tileSource =
{
Image:
{
xmlns: "http://schemas.microsoft.com/deepzoom/2008",
Url: "http://127.0.0.1/fcgi-bin/iipsrv.fcgi?
DeepZoom=E:/DeepZoomFile/10580_12079_1121935_stitch_files/",
Format: "jpg",
Overlap: "2",
TileSize: "256",
Size:
{
Height: "38290",
Width: "17953"
}
}
};
And the important line is :
Url: "http://127.0.0.1/fcgi-bin/iipsrv.fcgi?DeepZoom=E:/DeepZoomFile/10580_12079_1121935_stitch_files/"
I am getting errors from the browser that "fail to load tile image"
Any help or example of how should I do it ?
Thanks
No . It doesn't work with a suffix of DZI

How to determine if an SFTP file is a directory in Node.js?

The ssh2 library's SFTP readdir method gives me back all the files in the remote directory. How can I tell if any of of them are directories?
Here's some example output from the library:
{ filename:
'myfile',
longname:
'-rwxr-x--- 1 myuser mygroup 19036227 Nov 21 11:05 myfile',
attrs:
Stats {
mode: 33256,
permissions: 33256,
uid: 603,
gid: 1014,
size: 19036227,
atime: 1542859216,
mtime: 1542816340 } }
The file's mode contains bits indicating its type. You can check it like this:
const fs = require('fs');
function isDir(mode) {
return (mode & fs.constants.S_IFMT) == fs.constants.S_IFDIR;
}
isDir(myfile.attrs.mode);

Resources