Skip to content

Commit 0684c4b

Browse files
Add signal and abort controller to agent metadata and TakeAction button (#103217) (#103611)
Co-authored-by: Esteban Beltran <academo@users.noreply.github.com>
1 parent a6ebd0b commit 0684c4b

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

x-pack/plugins/security_solution/public/detections/containers/detection_engine/alerts/api.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,14 @@ export const getCaseIdsFromAlertId = async ({
178178
*
179179
* @param host id
180180
*/
181-
export const getHostMetadata = async ({ agentId }: { agentId: string }): Promise<HostInfo> =>
181+
export const getHostMetadata = async ({
182+
agentId,
183+
signal,
184+
}: {
185+
agentId: string;
186+
signal?: AbortSignal;
187+
}): Promise<HostInfo> =>
182188
KibanaServices.get().http.fetch<HostInfo>(
183189
resolvePathVariables(HOST_METADATA_GET_ROUTE, { id: agentId }),
184-
{ method: 'get' }
190+
{ method: 'GET', signal }
185191
);

x-pack/plugins/security_solution/public/detections/containers/detection_engine/alerts/use_host_isolation_status.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,23 @@ export const useHostIsolationStatus = ({
3838
const { addError } = useAppToasts();
3939

4040
useEffect(() => {
41+
const abortCtrl = new AbortController();
4142
// isMounted tracks if a component is mounted before changing state
4243
let isMounted = true;
4344
let fleetAgentId: string;
4445
const fetchData = async () => {
4546
try {
46-
const metadataResponse = await getHostMetadata({ agentId });
47+
const metadataResponse = await getHostMetadata({ agentId, signal: abortCtrl.signal });
4748
if (isMounted) {
4849
setIsIsolated(isEndpointHostIsolated(metadataResponse.metadata));
4950
setAgentStatus(metadataResponse.host_status);
5051
fleetAgentId = metadataResponse.metadata.elastic.agent.id;
5152
}
5253
} catch (error) {
54+
// don't show self-aborted requests errors to the user
55+
if (error.name === 'AbortError') {
56+
return;
57+
}
5358
addError(error.message, { title: ISOLATION_STATUS_FAILURE });
5459
}
5560

@@ -80,6 +85,7 @@ export const useHostIsolationStatus = ({
8085
return () => {
8186
// updates to show component is unmounted
8287
isMounted = false;
88+
abortCtrl.abort();
8389
};
8490
}, [addError, agentId]);
8591
return { loading, isIsolated, agentStatus, pendingIsolation, pendingUnisolation };

0 commit comments

Comments
 (0)