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

fix(app-shell,usb-bridge): improve flex usb communication #14170

Merged
merged 7 commits into from
Dec 12, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
bump keepalive to infinity
  • Loading branch information
sfoster1 committed Dec 11, 2023
commit e7a93425665854608ad8b4269fe93e391491eb0d
36 changes: 16 additions & 20 deletions app-shell/src/usb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ipcMain, IpcMainInvokeEvent } from 'electron'
import axios, { AxiosRequestConfig } from 'axios'
import axios, { AxiosRequestConfig, AxiosError } from 'axios'
import FormData from 'form-data'
import fs from 'fs'
import path from 'path'
Expand Down Expand Up @@ -34,19 +34,17 @@ let usbFetchInterval: NodeJS.Timeout
export function getSerialPortHttpAgent(): SerialPortHttpAgent | undefined {
return usbHttpAgent
}

export function createSerialPortHttpAgent(path: string): void {
const serialPortHttpAgent = new SerialPortHttpAgent({
maxFreeSockets: 1,
maxSockets: 1,
maxTotalSockets: 1,
keepAlive: true,
keepAliveMsecs: 10000,
keepAliveMsecs: Infinity,
Comment on lines -44 to +43
Copy link
Member

Choose a reason for hiding this comment

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

lol

path,
logger: usbLog,
timeout: 100000,
})

usbHttpAgent = serialPortHttpAgent
}

Expand All @@ -63,12 +61,10 @@ function isUsbDeviceOt3(device: UsbDevice): boolean {
device.vendorId === parseInt(DEFAULT_VENDOR_ID, 16)
)
}

async function usbListener(
_event: IpcMainInvokeEvent,
config: AxiosRequestConfig
): Promise<unknown> {
try {
// TODO(bh, 2023-05-03): remove mutation
let { data } = config
let formHeaders = {}
Expand All @@ -94,21 +90,21 @@ async function usbListener(
}

const usbHttpAgent = getSerialPortHttpAgent()

const response = await axios.request({
httpAgent: usbHttpAgent,
...config,
data,
headers: { ...config.headers, ...formHeaders },
})
return {
data: response.data,
status: response.status,
statusText: response.statusText,
}
try {
const response = await axios.request({
httpAgent: usbHttpAgent,
...config,
data,
headers: { ...config.headers, ...formHeaders },
})
return {
error: false,
data: response.data,
status: response.status,
statusText: response.statusText,
}
} catch (e) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
usbLog.debug(`usbListener error ${e?.message ?? 'unknown'}`)
console.log(`axios request error ${e?.message ?? 'unknown'}`)
Copy link
Member

Choose a reason for hiding this comment

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

was this changed cuz reading logs from the usb logger was annoying? cuz it seems like thats the right place to report logs here

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah how does one get logs out of the usb logger?

}
}

Expand Down