Skip to content

Commit

Permalink
fix(daemon): Various bug fixes (merge #1835)
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal authored Oct 18, 2023
2 parents 58e8d06 + 4aea6a3 commit 127f22f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
27 changes: 18 additions & 9 deletions packages/daemon/src/daemon-node-powers.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,22 @@ export const makeNetworkPowers = ({ http, ws, net }) => {
* @param {Promise<never>} args.cancelled
*/
const servePath = async ({ path, cancelled }) =>
serveListener(
server =>
new Promise(resolve =>
server.listen({ path }, () => resolve(undefined)),
),
cancelled,
);
serveListener(server => {
return new Promise((resolve, reject) =>
server.listen({ path }, error => {
if (error) {
if (path.length >= 104) {
console.warn(
`Warning: Length of path for domain socket or named path exceeeds common maximum (104, possibly 108) for some platforms (length: ${path.length}, path: ${path})`,
);
}
reject(error);
} else {
resolve(undefined);
}
}),
);
}, cancelled);

const connectionNumbers = (function* generateNumbers() {
let n = 0;
Expand All @@ -265,7 +274,7 @@ export const makeNetworkPowers = ({ http, ws, net }) => {
* @param {string} sockPath
* @param {Promise<never>} cancelled
* @param {(error: Error) => void} exitWithError
* @returns {{ started: () => Promise<void>, stopped: Promise<void> }}
* @returns {{ started: Promise<void>, stopped: Promise<void> }}
*/
const makePrivatePathService = (
endoBootstrap,
Expand All @@ -288,7 +297,7 @@ export const makeNetworkPowers = ({ http, ws, net }) => {
* @param {(port: Promise<number>) => void} assignWebletPort
* @param {Promise<never>} cancelled
* @param {(error: Error) => void} exitWithError
* @returns {{ started: () => Promise<void>, stopped: Promise<void> }}
* @returns {{ started: Promise<void>, stopped: Promise<void> }}
*/
const makePrivateHttpService = (
endoBootstrap,
Expand Down
2 changes: 1 addition & 1 deletion packages/daemon/src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ const makeEndoBootstrap = (
formula,
);

// Memoize provide.
// Memoize for lookup.
valuePromiseForFormulaIdentifier.set(formulaIdentifier, promiseForValue);

// Prepare an entry for reverse-lookup of formula for presence.
Expand Down
8 changes: 4 additions & 4 deletions packages/daemon/src/serve-private-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export const servePrivatePath = (
) => {
const connectionsP = servePath({ path: sockPath, cancelled });

const started = async () => {
const started = (async () => {
await connectionsP;
// Resolve a promise in the Endo CLI through the IPC channel:
console.log(
`Endo daemon listening for CapTP on ${q(
`Endo daemon listening for private CapTP on ${q(
sockPath,
)} ${new Date().toISOString()}`,
);
};
})();

const stopped = (async () => {
/** @type {Set<Promise<void>>} */
Expand All @@ -33,7 +33,7 @@ export const servePrivatePath = (
closed: connectionClosed,
} of connections) {
(async () => {
const connectionNumber = connectionNumbers.next();
const { value: connectionNumber } = connectionNumbers.next();
console.log(
`Endo daemon received domain connection ${connectionNumber} at ${new Date().toISOString()}`,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/daemon/src/serve-private-port-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const servePrivatePortHttp = (
closed: connectionClosed,
} = connection;

const connectionNumber = connectionNumbers.next();
const { value: connectionNumber } = connectionNumbers.next();
console.log(
`Endo daemon received local web socket connection ${connectionNumber} at ${new Date().toISOString()}`,
);
Expand Down
4 changes: 2 additions & 2 deletions packages/daemon/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,14 @@ export type NetworkPowers = {
sockPath: string,
cancelled: Promise<never>,
exitWithError: (error: Error) => void,
) => { started: () => Promise<void>; stopped: Promise<void> };
) => { started: Promise<void>; stopped: Promise<void> };
makePrivateHttpService: (
endoBootstrap: FarRef<unknown>,
port: number,
assignWebletPort: (portP: Promise<number>) => void,
cancelled: Promise<never>,
exitWithError: (error: Error) => void,
) => { started: () => Promise<void>; stopped: Promise<void> };
) => { started: Promise<void>; stopped: Promise<void> };
};

// The return type here is almost an EndoReadable, but not quite. Should fix.
Expand Down

0 comments on commit 127f22f

Please sign in to comment.