Skip to content

Commit

Permalink
feat(xen-api/getResource): detect invalid XAPI response
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-f committed Sep 26, 2024
1 parent 742109c commit ea5358e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- **xo-cli**
- `rest get --output $file` now displays progress information during download
- `rest post` and `rest put` now accept `--input $file` to upload a file and display progress information
- [Backup] Detect invalid VDI exports that are incorrectly reported as successful by XAPI

### Bug fixes

Expand All @@ -39,6 +40,7 @@

- @xen-orchestra/web minor
- @xen-orchestra/web-core minor
- xen-api minor
- xo-cli minor
- xo-server minor
<!--packages-end-->
30 changes: 29 additions & 1 deletion packages/xen-api/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import makeCallSetting from './_makeCallSetting.mjs'
import parseUrl from './_parseUrl.mjs'
import Ref from './_Ref.mjs'
import transports from './transports/index.mjs'
import { readChunk } from '@vates/read-chunk'

const { debug } = createLogger('xen-api')

Expand Down Expand Up @@ -104,7 +105,7 @@ export class Xapi extends EventEmitter {
this._createTransport = createTransport

this._addSyncStackTrace =
opts.syncStackTraces ?? process.env.NODE_ENV === 'development' ? addSyncStackTrace : identity
(opts.syncStackTraces ?? process.env.NODE_ENV === 'development') ? addSyncStackTrace : identity
this._callTimeout = makeCallSetting(opts.callTimeout, 60 * 60 * 1e3) // 1 hour but will be reduced in the future
this._httpInactivityTimeout = opts.httpInactivityTimeout ?? 5 * 60 * 1e3 // 5 mins
this._eventPollDelay = opts.eventPollDelay ?? 60 * 1e3 // 1 min
Expand Down Expand Up @@ -477,6 +478,33 @@ export class Xapi extends EventEmitter {
)
)

// 2024-09-26 - Work-around a XAPI bug: sometimes the response status is
// `200 OK` but the body contains a full HTTP response
//
// Example:
//
// ```http
// HTTP/1.1 500 Internal Error
// content-length: 357
// content-type:text/html
// connection:close
// cache-control:no-cache, no-store
//
// <html><body><h1>HTTP 500 internal server error</h1>An unexpected error occurred; please wait a while and try again. If the problem persists, please contact your support representative.<h1> Additional information </h1>SR_BACKEND_FAILURE_46: [ ; The VDI is not available [opterr=VDI d63513c8-b662-41cd-a355-a63efb5f073f not detached cleanly]; ]</body></html>
// ```
//
// Related GitHub issue: https://github.com/xapi-project/xen-api/issues/4603
//
// This code detects this and throw an error
const { body } = response
const chunk = await readChunk(body, 5)
body.unshift(chunk)
if (String(chunk) === 'HTTP/') {
const error = new Error('invalid HTTP header in response body')
Object.defineProperty(error, 'response', { value: response })
throw error
}

if (pTaskResult !== undefined) {
response.task = pTaskResult
}
Expand Down
1 change: 1 addition & 0 deletions packages/xen-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@vates/decorate-with": "^2.1.0",
"@vates/json-hash": "^0.2.0",
"@vates/obfuscate": "^0.1.0",
"@vates/read-chunk": "^1.2.0",
"@vates/xml": "^2.0.0",
"@vates/xml-rpc": "^1.0.0",
"@xen-orchestra/log": "^0.6.0",
Expand Down

0 comments on commit ea5358e

Please sign in to comment.