Open lassejlv opened 1 month ago
~Duplicate of #8228~
on mac x86 13.5.2 (Ventura) the error was similar when trying launch an ssh2 server
dyld[26567]: missing symbol called
Abort trap: 6
on linux x86 ubuntu server
bun: symbol lookup error: /PATH/TO/src/node_modules/cpu-features/build/Release/cpufeatures.node: undefined symbol: node_module_register
import { readFileSync } from 'fs';
import { Server, type AuthContext } from 'ssh2';
import net from 'net';
/**
* SSH server's initial configurations.
*/
type ServerConfigurations<T extends AuthContext> = {
/**
* Path to the host key file.
*/
hostKeyPath: string | undefined;
/**
* Authenticates an SSH connection.
*/
authenticate: (context: T) => Promise<boolean>;
/**
* Retrieves an assigned port for local forwarding.
*/
assignPort: (context: T) => Promise<number>;
};
/**
* Creates an SSH server that supports local port forwarding with authentication.
*/
function createServer<T extends AuthContext>({
hostKeyPath,
authenticate,
assignPort,
}: ServerConfigurations<T>) {
const hostKeys = [] as string[];
if (hostKeyPath) {
hostKeys.push(Buffer.from(readFileSync(hostKeyPath)).toString());
}
return new Server(
{
hostKeys,
},
(client) => {
client
.on('authentication', async (ctx) => {
if (!(await authenticate(ctx as T))) {
return ctx.reject();
}
(client as any).assignedPort = await assignPort(ctx as T);
return ctx.accept();
})
.on('ready', () => {
client.on('request', (accept, reject, name, info) => {
if (name === 'tcpip-forward') {
const assignedPort = (client as any)
.assignedPort as number;
if (assignedPort === info.bindPort) {
const server = net
.createServer((socket) => {
socket.setEncoding('utf8');
client.forwardOut(
info.bindAddr,
info.bindPort,
String(socket.remoteAddress),
Number(socket.remotePort),
(err, upstream) => {
if (err) {
console.log(err);
socket.end();
return;
}
upstream
.pipe(socket)
.pipe(upstream);
},
);
})
.listen(info.bindPort);
(client as any).server = server;
return accept && accept();
}
}
return reject && reject();
});
client.on('close', () => {
((client as any).server as net.Server)?.close();
});
});
},
);
}
/**
* SSH functionalities.
*/
export default {
createServer,
};
These scripts work well in my python:3.11-slim
container with Bun 1.1.17 installed. The only drawback is that I could not build it 😭 by using the bun build
command:
error: Could not resolve: "../build/Release/cpufeatures.node"
What version of Bun is running?
1.1.13+bd6a60512
What platform is your computer?
Darwin 23.5.0 arm64 arm
What steps can reproduce the bug?
You can use this code:
What is the expected behavior?
I would expect it to connect and run commands. It works with node without any issues.
What do you see instead?
With bun it just exists with this error:
Additional information
Nope, love bun keep up the great work!