mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-24 10:54:04 +08:00
Add a port timeout detection feature for gradio/preview. (#9707)
* Add a port timeout detection feature for gradio/preview. This feature can help users receive more informative messages when running 'gradio cc dev' in case of network issues * add changeset * add changeset * fix --------- Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com> Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
cd7dab7ba5
commit
8d848dd1e4
5
.changeset/honest-forks-pay.md
Normal file
5
.changeset/honest-forks-pay.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@gradio/preview": patch
|
||||
---
|
||||
|
||||
fix:Add a port timeout detection feature for gradio/preview.
|
@ -129,6 +129,12 @@ export async function find_free_ports(
|
||||
export function is_free_port(port: number): Promise<boolean> {
|
||||
return new Promise((accept, reject) => {
|
||||
const sock = net.createConnection(port, "127.0.0.1");
|
||||
setTimeout(() => {
|
||||
sock.destroy();
|
||||
reject(
|
||||
new Error(`Timeout while detecting free port with 127.0.0.1:${port} `)
|
||||
);
|
||||
}, 3000);
|
||||
sock.once("connect", () => {
|
||||
sock.end();
|
||||
accept(false);
|
||||
|
Loading…
Reference in New Issue
Block a user