Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve port handling #206

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion executor/pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
],
"main": "chopsticks_executor.js",
"types": "chopsticks_executor.d.ts"
}
}
5 changes: 3 additions & 2 deletions packages/chopsticks/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { isUrl } from './utils'
import { runBlock } from './run-block'

const processConfig = async (path: string) => {
let file
let file: string
if (isUrl(path)) {
file = await axios.get(path).then((x) => x.data)
} else {
Expand All @@ -26,8 +26,9 @@ const processConfig = async (path: string) => {

const processArgv = async (argv: any) => {
if (argv.config) {
return { ...(await processConfig(argv.config)), ...argv }
argv = { ...(await processConfig(argv.config)), ...argv }
}
argv.port = argv.port ?? (process.env.PORT ? Number(process.env.PORT) : 8000)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cli overrides config file overrides env. maybe we want env to be top priority?

return argv
}

Expand Down
2 changes: 1 addition & 1 deletion packages/chopsticks/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const createServer = async (handler: Handler, port?: number) => {
let wss: WebSocketServer | undefined
let listenPort: number | undefined
for (let i = 0; i < 5; i++) {
const preferPort = (port || 0) + i
const preferPort = (port ?? 0) > 0 ? (port ?? 0) + i : 0
logger.debug('Try starting on port %d', preferPort)
const [maybeWss, maybeListenPort] = await createWS(preferPort)
if (maybeWss && maybeListenPort) {
Expand Down
2 changes: 1 addition & 1 deletion packages/chopsticks/src/setup-with-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { setup } from './setup'

export const setupWithServer = async (argv: Config) => {
const context = await setup(argv)
const port = argv.port || Number(process.env.PORT) || 8000
const port = argv.port ?? 8000

if (argv.genesis) {
// mine 1st block when starting from genesis to set some mock validation data
Expand Down