Skip to content

Commit

Permalink
Add debug logs for dev's issue
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteregrets committed Dec 24, 2023
1 parent 4190594 commit b4d5830
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mirrord/layer/src/file/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ use mirrord_protocol::file::{
WriteFileResponse, XstatFsResponse, XstatResponse,
};
use rand::distributions::{Alphanumeric, DistString};
use tracing::{error, trace};
use tracing::{debug, error, trace};

use super::{hooks::FN_OPEN, open_dirs::OPEN_DIRS, *};
use crate::{
common,
detour::{Bypass, Detour},
error::{HookError, HookResult as Result},
};

/// 1 Megabyte. Large read requests can lead to timeouts.
const MAX_READ_SIZE: u64 = 1024 * 1024;

Expand Down Expand Up @@ -154,6 +153,11 @@ fn close_remote_file_on_failure(fd: u64) -> Result<()> {
/// [`OPEN_FILES`].
#[tracing::instrument(level = "trace", ret)]
pub(crate) fn open(path: Detour<PathBuf>, open_options: OpenOptionsInternal) -> Detour<RawFd> {
debug!(
"open-ish called | OPEN_FILES: {:#?}, path: {:#?}",
OPEN_FILES, path
);

let path = path?;

if path.is_relative() {
Expand All @@ -175,6 +179,8 @@ pub(crate) fn open(path: Detour<PathBuf>, open_options: OpenOptionsInternal) ->
Arc::new(RemoteFile::new(remote_fd, path.display().to_string())),
);

debug!("open-ish after insertion | OPEN_FILES: {:#?}", OPEN_FILES);

Detour::Success(local_file_fd)
}

Expand Down
4 changes: 4 additions & 0 deletions mirrord/layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ use mirrord_layer_macro::{hook_fn, hook_guard_fn};
use proxy_connection::ProxyConnection;
use setup::LayerSetup;
use socket::SOCKETS;
use tracing::debug;
use tracing_subscriber::{fmt::format::FmtSpan, prelude::*};

use crate::{debugger_ports::DebuggerPorts, detour::DetourGuard, load::LoadType};
Expand Down Expand Up @@ -456,13 +457,16 @@ fn enable_hooks(enabled_file_ops: bool, enabled_remote_dns: bool, patch_binaries
/// **DON'T ADD LOGS HERE SINCE CALLER MIGHT CLOSE STDOUT/STDERR CAUSING THIS TO CRASH**
pub(crate) fn close_layer_fd(fd: c_int) {
// Remove from sockets.
debug!("Closing, OPEN_FILES: {:?}", fd, OPEN_FILES);

Check failure on line 460 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / check-rust-docs

argument never used

Check failure on line 460 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / integration_tests

argument never used

Check failure on line 460 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / lint

argument never used

Check failure on line 460 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / macos_tests

argument never used

Check failure on line 460 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / e2e (docker)

argument never used

Check failure on line 460 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / e2e (containerd)

argument never used

Check failure on line 460 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / build_binaries_x86_64-unknown-linux-gnu

argument never used

Check failure on line 460 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / build_binaries_aarch64-unknown-linux-gnu

argument never used

Check failure on line 460 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / build_binaries_macos

argument never used
if let Some((_, socket)) = SOCKETS.remove(&fd) {
// Closed file is a socket, so if it's already bound to a port - notify agent to stop
// mirroring/stealing that port.
socket.close();
} else if setup().fs_config().is_active() {
OPEN_FILES.remove(&fd);
}

debug!("Closed, OPEN_FILES: {:?}", fd, OPEN_FILES);

Check failure on line 469 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / check-rust-docs

argument never used

Check failure on line 469 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / integration_tests

argument never used

Check failure on line 469 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / lint

argument never used

Check failure on line 469 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / macos_tests

argument never used

Check failure on line 469 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / e2e (docker)

argument never used

Check failure on line 469 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / e2e (containerd)

argument never used

Check failure on line 469 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / build_binaries_x86_64-unknown-linux-gnu

argument never used

Check failure on line 469 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / build_binaries_aarch64-unknown-linux-gnu

argument never used

Check failure on line 469 in mirrord/layer/src/lib.rs

View workflow job for this annotation

GitHub Actions / build_binaries_macos

argument never used
}

// TODO: When this is annotated with `hook_guard_fn`, then the outgoing sockets never call it (we
Expand Down

0 comments on commit b4d5830

Please sign in to comment.