Skip to content

Commit

Permalink
use port: undefined vs 0 for UserWorker
Browse files Browse the repository at this point in the history
to force different port across reloads to workaround workerd bug on Windows
  • Loading branch information
RamIdeas committed Nov 2, 2023
1 parent 2909265 commit 6b99cab
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fixtures/dev-env/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function fakeStartUserWorker(options: {
};
const mfOpts: MiniflareOptions = Object.assign(
{
port: 0,
port: undefined,
inspectorPort: 0,
modules: true,
compatibilityDate: "2023-08-01",
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/dev/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ function DevSession(props: DevSessionProps) {
bindings={props.bindings}
workerDefinitions={workerDefinitions}
assetPaths={props.assetPaths}
initialPort={0} // hard-code for userworker, DevEnv-ProxyWorker now uses this prop value
initialPort={undefined} // hard-code for userworker, DevEnv-ProxyWorker now uses this prop value
initialIp={"127.0.0.1"} // hard-code for userworker, DevEnv-ProxyWorker now uses this prop value
rules={props.rules}
inspectorPort={props.inspectorPort}
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/dev/local.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface LocalProps {
bindings: CfWorkerInit["bindings"];
workerDefinitions: WorkerRegistry | undefined;
assetPaths: AssetPaths | undefined;
initialPort: number;
initialPort: number | undefined;
initialIp: string;
rules: Config["rules"];
inspectorPort: number;
Expand Down
7 changes: 6 additions & 1 deletion packages/wrangler/src/dev/miniflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export default {
}
`;

type SpecificPort = Exclude<number, 0>;
type RandomConsistentPort = 0; // random port, but consistent across reloads
type RandomDifferentPort = undefined; // random port, but different across reloads
type Port = SpecificPort | RandomConsistentPort | RandomDifferentPort;

export interface ConfigBundle {
// TODO(soon): maybe rename some of these options, check proposed API Google Docs
name: string | undefined;
Expand All @@ -91,7 +96,7 @@ export interface ConfigBundle {
bindings: CfWorkerInit["bindings"];
workerDefinitions: WorkerRegistry | undefined;
assetPaths: AssetPaths | undefined;
initialPort: number;
initialPort: Port;
initialIp: string;
rules: Config["rules"];
inspectorPort: number;
Expand Down

0 comments on commit 6b99cab

Please sign in to comment.