Skip to content

Commit

Permalink
Merge pull request #8714 from habitat-sh/jj/windows-7-support
Browse files Browse the repository at this point in the history
Fix windows 7 support
  • Loading branch information
mwrock committed Jan 18, 2023
2 parents 6d55b79 + 97eff71 commit 1f6070e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion components/launcher-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ env_logger = "*"
habitat_core = { path = "../core" }
habitat-launcher-protocol = { path = "../launcher-protocol" }
habitat_common = { path = "../common" }
ipc-channel = { version = "*" }
# TODO: In order to support certain customers who are still using Windows 7 until
# January 2024, it is necessary to freeze the version of this crate at 0.15.0.
# Newer versions of this crate use a Windows syscall called 'GetOverlappedResultEx',
# which is not supported on versions of Windows prior to 8.
# For more information about 'GetOverlappedResultEx', please refer to the following documentation: https://learn.microsoft.com/en-us/windows/win32/api/ioapiset/nf-ioapiset-getoverlappedresultex
# The commit that introduced the change can be found here: https://github.com/servo/ipc-channel/commit/eb08381a30bc71a534a0a73ab98c05bca7a12f82
ipc-channel = { version = "0.15.0" }
libc = "*"
log = "*"
prost = "*"
Expand Down
25 changes: 14 additions & 11 deletions components/launcher-client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::error::{ConnectError,
IPCCommandError,
IPCReadError,
ReceiveError,
SendError,
TryIPCCommandError,
TryReceiveError};
use crate::{error::{ConnectError,
IPCCommandError,
IPCReadError,
ReceiveError,
SendError,
TryIPCCommandError,
TryReceiveError},
IPCError};
use habitat_common::types::UserInfo;
use habitat_core::os::process::Pid;
use habitat_launcher_protocol as protocol;
Expand Down Expand Up @@ -93,7 +94,7 @@ impl LauncherCli {
{
match rx.recv() {
Ok(bytes) => Ok(Self::read(&bytes)?),
Err(err) => Err(ReceiveError::IPCReceive(err)),
Err(err) => Err(ReceiveError::IPCReceive(err.into())),
}
}

Expand Down Expand Up @@ -131,7 +132,7 @@ impl LauncherCli {
thread::sleep(Duration::from_millis(5));
}
Err(TryRecvError::IpcError(err)) => {
return Err(TryReceiveError::IPCReceive(err));
return Err(TryReceiveError::IPCReceive(err.into()));
}
}
if start_time.elapsed() > timeout {
Expand Down Expand Up @@ -160,7 +161,7 @@ impl LauncherCli {
Ok(Some(msg))
}
Err(TryRecvError::Empty) => Ok(None),
Err(TryRecvError::IpcError(err)) => Err(ReceiveError::IPCReceive(err)),
Err(TryRecvError::IpcError(err)) => Err(ReceiveError::IPCReceive(err.into())),
}
}

Expand All @@ -171,7 +172,9 @@ impl LauncherCli {
// Received a shutdown command
Ok(Some(_)) => LauncherStatus::GracefullyShutdown,
// Launcher IPC channel was disconnected
Err(ReceiveError::IPCReceive(IpcError::Disconnected)) => LauncherStatus::Shutdown,
Err(ReceiveError::IPCReceive(IPCError(IpcError::Disconnected))) => {
LauncherStatus::Shutdown
}
// Received a bad message, or encountered an IO error while communicating via IPC
Err(err) => {
error!("Unexpected IPC communication error while checking for a shutdown \
Expand Down
40 changes: 37 additions & 3 deletions components/launcher-client/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use habitat_launcher_protocol as protocol;
use std::io;
use ipc_channel::ipc::IpcError;
use std::{fmt,
io};
use thiserror::Error;

/// Errors that occur when attempting to estabish an IPC channel to the Habitat Launcher
Expand Down Expand Up @@ -64,7 +66,7 @@ pub enum ReceiveError {
#[error("Failed to read launcher command response")]
IPCRead(#[from] IPCReadError),
#[error("Failed to receive IPC command response from launcher")]
IPCReceive(#[from] ipc_channel::ipc::IpcError),
IPCReceive(#[from] IPCError),
}

/// Errors that occur when attempting to non-blocking receive command responses from the Habitat
Expand All @@ -74,7 +76,39 @@ pub enum TryReceiveError {
#[error("Failed to try reading launcher command response")]
IPCRead(#[from] IPCReadError),
#[error("Failed to try receiving IPC command response from launcher")]
IPCReceive(#[from] ipc_channel::ipc::IpcError),
IPCReceive(#[from] IPCError),
#[error("Timed out trying to receive IPC command response from launcher")]
Timeout,
}

// TODO: Remove this wrapper type once we upgrade ipc-channel to 0.16+
// This is a wrapper type around the ipc_channel::ipc::IpcError that is
// required because it does not implement std::error::Error prior to
// version 0.16+. We need an older version of the crate to ensure that
// habitat works for some of our customers using Windows 7 until Jan 2024.
#[derive(Debug)]
pub struct IPCError(pub ipc_channel::ipc::IpcError);

impl From<ipc_channel::ipc::IpcError> for IPCError {
fn from(value: ipc_channel::ipc::IpcError) -> Self { IPCError(value) }
}

impl fmt::Display for IPCError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match self.0 {
IpcError::Bincode(ref err) => write!(fmt, "bincode error: {}", err),
IpcError::Io(ref err) => write!(fmt, "io error: {}", err),
IpcError::Disconnected => write!(fmt, "disconnected"),
}
}
}

impl std::error::Error for IPCError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self.0 {
IpcError::Bincode(ref err) => Some(err),
IpcError::Io(ref err) => Some(err),
IpcError::Disconnected => None,
}
}
}
8 changes: 7 additions & 1 deletion components/launcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ env_logger = "*"
habitat_common = { path = "../common" }
habitat_core = { path = "../core" }
habitat-launcher-protocol = { path = "../launcher-protocol" }
ipc-channel = { version = "*" }
# TODO: In order to support certain customers who are still using Windows 7 until
# January 2024, it is necessary to freeze the version of this crate at 0.15.0.
# Newer versions of this crate use a Windows syscall called 'GetOverlappedResultEx',
# which is not supported on versions of Windows prior to 8.
# For more information about 'GetOverlappedResultEx', please refer to the following documentation: https://learn.microsoft.com/en-us/windows/win32/api/ioapiset/nf-ioapiset-getoverlappedresultex
# The commit that introduced the change can be found here: https://github.com/servo/ipc-channel/commit/eb08381a30bc71a534a0a73ab98c05bca7a12f82
ipc-channel = { version = "0.15.0" }
libc = "*"
log = "*"
prost = "*"
Expand Down

0 comments on commit 1f6070e

Please sign in to comment.