승인된 작업의 앱 전체 시간 제한을 해제한다
- 작성자
- 호시노 히나타
- 작성 시각
- 커밋
dcae9b1c37455d5daeb7945ed321b6c6050fb610- 부모
- f2d6db3
변경된 파일 4개
+203-2| @@ -337,6 +337,12 @@ fn fault(events: &SyncSender<ui::HostEvent>, stop: &AtomicBool, message: &str) { | ||
| 337 | 337 | notify(events, ui::HostEvent::Fault(message.into())); |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 추가: #[derive(Default)] | |
| 341 | 추가: struct ResourceDeadline { | |
| 342 | 추가: pending: Option<(u64, wire::ResourceScope)>, | |
| 343 | 추가: approved: bool, | |
| 344 | 추가: } | |
| 345 | 추가: | |
| 340 | 346 | pub struct ProcessFactory { |
| 341 | 347 | worker: PathBuf, |
| 342 | 348 | } |
| @@ -366,10 +372,12 @@ impl ui::Factory for ProcessFactory { | ||
| 366 | 372 | let stop = Arc::new(AtomicBool::new(false)); |
| 367 | 373 | let done = Arc::new(AtomicBool::new(false)); |
| 368 | 374 | let expected = Arc::new(Mutex::new(None)); |
| 375 | 추가: let resources = Arc::new(Mutex::new(ResourceDeadline::default())); | |
| 369 | 376 | let worker = self.worker.clone(); |
| 370 | 377 | let worker_stop = stop.clone(); |
| 371 | 378 | let worker_done = done.clone(); |
| 372 | 379 | let worker_expected = expected.clone(); |
| 380 | 추가: let worker_resources = resources.clone(); | |
| 373 | 381 | let supervisor = thread::Builder::new() |
| 374 | 382 | .name("zipelo-worker-owner".into()) |
| 375 | 383 | .spawn(move || { |
| @@ -407,6 +415,7 @@ impl ui::Factory for ProcessFactory { | ||
| 407 | 415 | worker_stop, |
| 408 | 416 | worker_done, |
| 409 | 417 | worker_expected, |
| 418 | 추가: worker_resources, | |
| 410 | 419 | ); |
| 411 | 420 | }) |
| 412 | 421 | .map_err(|_| "작업자 관리 스레드를 시작하지 못했습니다")?; |
| @@ -423,6 +432,7 @@ impl ui::Factory for ProcessFactory { | ||
| 423 | 432 | stop, |
| 424 | 433 | supervisor: Some(supervisor), |
| 425 | 434 | expected, |
| 435 | 추가: resources, | |
| 426 | 436 | done, |
| 427 | 437 | disconnected: false, |
| 428 | 438 | reaped: false, |
| @@ -451,6 +461,7 @@ struct ProcessConnection { | ||
| 451 | 461 | stop: Arc<AtomicBool>, |
| 452 | 462 | supervisor: Option<JoinHandle<()>>, |
| 453 | 463 | expected: Arc<Mutex<Option<wire::ActionKind>>>, |
| 464 | 추가: resources: Arc<Mutex<ResourceDeadline>>, | |
| 454 | 465 | done: Arc<AtomicBool>, |
| 455 | 466 | disconnected: bool, |
| 456 | 467 | reaped: bool, |
| @@ -513,6 +524,10 @@ impl ui::Connection for ProcessConnection { | ||
| 513 | 524 | self.stop.store(true, Ordering::Release); |
| 514 | 525 | return Err("작업자 요청을 직렬화하지 못했습니다".into()); |
| 515 | 526 | } |
| 527 | 추가: let mut resources = self.resources.lock().map_err(|_| { | |
| 528 | 추가: self.stop.store(true, Ordering::Release); | |
| 529 | 추가: "작업자 승인 상태 오류" | |
| 530 | 추가: })?; | |
| 516 | 531 | let bytes = Frame(std::mem::take(&mut *self.buffer.0.borrow_mut()), is_cancel); |
| 517 | 532 | if self.send.as_ref().unwrap().try_send(bytes).is_err() { |
| 518 | 533 | if is_cancel && self.done.load(Ordering::Acquire) { |
| @@ -522,6 +537,16 @@ impl ui::Connection for ProcessConnection { | ||
| 522 | 537 | self.stop.store(true, Ordering::Release); |
| 523 | 538 | return Err("작업자 요청 대기열이 닫혔거나 가득 찼습니다".into()); |
| 524 | 539 | } |
| 540 | 추가: if let wire::Message::ResourceReply { | |
| 541 | 추가: challenge_id, | |
| 542 | 추가: scope, | |
| 543 | 추가: allow, | |
| 544 | 추가: } = message | |
| 545 | 추가: && resources.pending == Some((challenge_id, scope)) | |
| 546 | 추가: { | |
| 547 | 추가: resources.approved |= allow; | |
| 548 | 추가: resources.pending = None; | |
| 549 | 추가: } | |
| 525 | 550 | self.next += 1; |
| 526 | 551 | Ok(()) |
| 527 | 552 | } |
| @@ -563,6 +588,7 @@ fn supervise( | ||
| 563 | 588 | stop: Arc<AtomicBool>, |
| 564 | 589 | done: Arc<AtomicBool>, |
| 565 | 590 | expected: Arc<Mutex<Option<wire::ActionKind>>>, |
| 591 | 추가: resources: Arc<Mutex<ResourceDeadline>>, | |
| 566 | 592 | ) { |
| 567 | 593 | let mut input = child.stdin.take().unwrap(); |
| 568 | 594 | let mut output = child.stdout.take().unwrap(); |
| @@ -604,6 +630,7 @@ fn supervise( | ||
| 604 | 630 | let tx = events.clone(); |
| 605 | 631 | let abort = stop.clone(); |
| 606 | 632 | let received_terminal = terminal_received.clone(); |
| 633 | 추가: let pending_resource = resources.clone(); | |
| 607 | 634 | threads.push( |
| 608 | 635 | thread::Builder::new() |
| 609 | 636 | .name("zipelo-worker-output".into()) |
| @@ -620,6 +647,14 @@ fn supervise( | ||
| 620 | 647 | fault(&tx, &abort, "작업자 응답이 요청과 일치하지 않습니다"); |
| 621 | 648 | break false; |
| 622 | 649 | } |
| 650 | 추가: if let Ok(ui::Event::ResourceRequired(question)) = &event { | |
| 651 | 추가: if let Ok(mut state) = pending_resource.lock() { | |
| 652 | 추가: state.pending = Some((question.id, question.scope)); | |
| 653 | 추가: } else { | |
| 654 | 추가: fault(&tx, &abort, "작업자 승인 상태 오류"); | |
| 655 | 추가: break false; | |
| 656 | 추가: } | |
| 657 | 추가: } | |
| 623 | 658 | if matches!(event, Ok(ui::Event::Terminal(_))) { |
| 624 | 659 | received_terminal.store(true, Ordering::Release); |
| 625 | 660 | } |
| @@ -679,7 +714,13 @@ fn supervise( | ||
| 679 | 714 | } |
| 680 | 715 | let started = Instant::now(); |
| 681 | 716 | let status = loop { |
| 682 | 삭제: if started.elapsed() >= Duration::from_secs(310) { | |
| 717 | 추가: // 승인 뒤 실제 진행과 질문 대기 시간은 작업자의 60초 정체 감시로 판단함. | |
| 718 | 추가: // 응답 프레임 간격을 실제 파일 처리 진행으로 간주하지 않음. | |
| 719 | 추가: let approved = resources | |
| 720 | 추가: .lock() | |
| 721 | 추가: .map(|state| state.approved) | |
| 722 | 추가: .unwrap_or(false); | |
| 723 | 추가: if !approved && started.elapsed() >= Duration::from_secs(310) { | |
| 683 | 724 | fault(&events, &stop, "작업자 처리 제한 시간을 초과했습니다"); |
| 684 | 725 | } |
| 685 | 726 | if stop.load(Ordering::Acquire) { |
| @@ -10,7 +10,7 @@ PATH나 현재 작업 폴더에서 임의 작업자를 검색하지 않음. ui-f | ||
| 10 | 10 | 정상 종료에는 Terminal, 양쪽 EOF와 child wait를 모두 확인함. 통신 오류는 성공으로 |
| 11 | 11 | 표시하지 않으며, 오류 경로에서는 child 회수와 모든 파이프 스레드/핸들 정리가 끝났다는 |
| 12 | 12 | 명시적 완료 신호까지 확인함. 연결이 예외적으로 폐기돼도 소유한 자식을 종료하고 회수함. |
| 13 | 삭제: 310초 제한 시간을 넘긴 작업자도 종료와 회수를 시도하며 완료 여부가 불명확하면 닫기를 허용하지 않음. | |
| 13 | 추가: 확대 승인 전에는 기존 310초 제한과 강제 종료 및 회수를 유지함. 유효한 자원 질문과 일치하는 허용 응답이 요청 큐에 들어간 뒤에는 앱의 전체 시간 제한을 해제함. 승인 뒤 실제 진행 없는 60초와 질문별 응답 대기 300초는 작업자의 Watchdog에서 판단하며, 앱은 응답 프레임을 실제 진행으로 추정하지 않음. 암호/충돌/자원 질문에 답하는 시간은 정체 시간에 포함하지 않음. 완료 여부가 불명확하면 닫기를 허용하지 않음. | |
| 14 | 14 | |
| 15 | 15 | ## 실행 |
| 16 | 16 | |
| @@ -67,3 +67,5 @@ formats.rs는 전체 ListEnd 프레임을 고정 바이트와 비교하고 Unix/ | ||
| 67 | 67 | 목록 응답과 해제 요청 사이에서 보존되는지 확인함. 화면 흐름 시험은 PR69의 LZMA와 |
| 68 | 68 | LZMA2 표본을 실제 작업자로 열고, 받은 ListId로 풀어 원본 바이트를 확인함. |
| 69 | 69 | 구버전 앱은 새 형식 값을 해석할 수 없으므로 앱과 작업자를 함께 갱신해야 함. |
| 70 | 추가: | |
| 71 | 추가: 가상 시계 회귀 approved_password_wait_is_not_killed_by_app_deadline은 정상 시계 대조군, 승인 뒤 관리 스레드의 311초 경과와 암호 대기, 승인하지 않은 작업의 기존 강제 종료를 실제 작업자 파이프로 검증함. 시계는 별도 시험 프로세스의 관리 스레드에만 적용하며 실제 310초를 기다리지 않음. |
| @@ -166,3 +166,143 @@ fn approved_extraction_reports_implicit_parents_separately_from_entries() { | ||
| 166 | 166 | ); |
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 추가: | |
| 170 | 추가: #[cfg(target_os = "linux")] | |
| 171 | 추가: #[test] | |
| 172 | 추가: fn approved_password_wait_is_not_killed_by_app_deadline() { | |
| 173 | 추가: const MODE: &str = "ZIPELO_SUPERVISOR_CLOCK_CASE"; | |
| 174 | 추가: if let Ok(mode) = std::env::var(MODE) { | |
| 175 | 추가: let approved = mode != "unapproved"; | |
| 176 | 추가: let scratch = Scratch::new(); | |
| 177 | 추가: let output = scratch.path("output.zip"); | |
| 178 | 추가: let mut factory = ProcessFactory::new(binary("zipelo-archive-worker")); | |
| 179 | 추가: let mut connection = factory.connect(1).unwrap(); | |
| 180 | 추가: let start = Start::CreateZip { | |
| 181 | 추가: sources: vec![(scratch.path("source.txt"), "source.txt".into())], | |
| 182 | 추가: output_file: output.clone(), | |
| 183 | 추가: method: Method::Store, | |
| 184 | 추가: aes256: true, | |
| 185 | 추가: }; | |
| 186 | 추가: fs::write(scratch.path("source.txt"), b"source").unwrap(); | |
| 187 | 추가: connection | |
| 188 | 추가: .send(Request { | |
| 189 | 추가: job_id: 1, | |
| 190 | 추가: sequence: 0, | |
| 191 | 추가: command: if approved { | |
| 192 | 추가: Command::StartExpanded(start) | |
| 193 | 추가: } else { | |
| 194 | 추가: Command::Start(start) | |
| 195 | 추가: }, | |
| 196 | 추가: }) | |
| 197 | 추가: .unwrap(); | |
| 198 | 추가: let started = Instant::now(); | |
| 199 | 추가: let mut sequence = 1; | |
| 200 | 추가: let mut granted = false; | |
| 201 | 추가: let mut password = false; | |
| 202 | 추가: let mut cancelled = false; | |
| 203 | 추가: let mut terminal = None; | |
| 204 | 추가: let mut fault = None; | |
| 205 | 추가: loop { | |
| 206 | 추가: if let Some(event) = connection.poll() { | |
| 207 | 추가: match event { | |
| 208 | 추가: HostEvent::Frame { | |
| 209 | 추가: event: Event::ResourceRequired(q), | |
| 210 | 추가: .. | |
| 211 | 추가: } => { | |
| 212 | 추가: assert!(approved); | |
| 213 | 추가: connection | |
| 214 | 추가: .send(Request { | |
| 215 | 추가: job_id: 1, | |
| 216 | 추가: sequence, | |
| 217 | 추가: command: Command::ResourceReply { | |
| 218 | 추가: challenge_id: q.id, | |
| 219 | 추가: scope: q.scope, | |
| 220 | 추가: allow: true, | |
| 221 | 추가: }, | |
| 222 | 추가: }) | |
| 223 | 추가: .unwrap(); | |
| 224 | 추가: sequence += 1; | |
| 225 | 추가: granted = true; | |
| 226 | 추가: } | |
| 227 | 추가: HostEvent::Frame { | |
| 228 | 추가: event: Event::PasswordRequired { .. }, | |
| 229 | 추가: .. | |
| 230 | 추가: } => password = true, | |
| 231 | 추가: HostEvent::Frame { | |
| 232 | 추가: event: Event::Terminal(value), | |
| 233 | 추가: .. | |
| 234 | 추가: } => terminal = Some(value), | |
| 235 | 추가: HostEvent::Fault(message) => fault = Some(message), | |
| 236 | 추가: HostEvent::Exited { success } => { | |
| 237 | 추가: assert!(password); | |
| 238 | 추가: assert_eq!(granted, approved); | |
| 239 | 추가: assert!(!output.exists()); | |
| 240 | 추가: if approved { | |
| 241 | 추가: assert!(success); | |
| 242 | 추가: assert!( | |
| 243 | 추가: fault.is_none(), | |
| 244 | 추가: "승인 뒤 암호 대기를 강제 종료함: {fault:?}" | |
| 245 | 추가: ); | |
| 246 | 추가: assert_eq!(terminal.unwrap().outcome, Outcome::Cancelled); | |
| 247 | 추가: } else { | |
| 248 | 추가: assert!(!success); | |
| 249 | 추가: assert!(fault.unwrap().contains("제한 시간")); | |
| 250 | 추가: } | |
| 251 | 추가: return; | |
| 252 | 추가: } | |
| 253 | 추가: _ => {} | |
| 254 | 추가: } | |
| 255 | 추가: } | |
| 256 | 추가: if approved && started.elapsed() > Duration::from_secs(4) && !cancelled { | |
| 257 | 추가: connection | |
| 258 | 추가: .send(Request { | |
| 259 | 추가: job_id: 1, | |
| 260 | 추가: sequence, | |
| 261 | 추가: command: Command::Cancel, | |
| 262 | 추가: }) | |
| 263 | 추가: .unwrap(); | |
| 264 | 추가: cancelled = true; | |
| 265 | 추가: } | |
| 266 | 추가: assert!(started.elapsed() < Duration::from_secs(8)); | |
| 267 | 추가: std::thread::sleep(Duration::from_millis(1)); | |
| 268 | 추가: } | |
| 269 | 추가: } | |
| 270 | 추가: let scratch = Scratch::new(); | |
| 271 | 추가: let clock = scratch.path("supervisor-clock.so"); | |
| 272 | 추가: assert!( | |
| 273 | 추가: std::process::Command::new("cc") | |
| 274 | 추가: .args(["-shared", "-fPIC", "-pthread"]) | |
| 275 | 추가: .arg( | |
| 276 | 추가: Path::new(env!("CARGO_MANIFEST_DIR")) | |
| 277 | 추가: .join("../../tests/rust-app-real-worker/supervisor_clock.c") | |
| 278 | 추가: ) | |
| 279 | 추가: .args(["-o"]) | |
| 280 | 추가: .arg(&clock) | |
| 281 | 추가: .arg("-ldl") | |
| 282 | 추가: .status() | |
| 283 | 추가: .unwrap() | |
| 284 | 추가: .success() | |
| 285 | 추가: ); | |
| 286 | 추가: for mode in ["control", "approved", "unapproved"] { | |
| 287 | 추가: let mut command = std::process::Command::new(std::env::current_exe().unwrap()); | |
| 288 | 추가: command | |
| 289 | 추가: .args([ | |
| 290 | 추가: "--exact", | |
| 291 | 추가: "guarded_flows::approved_password_wait_is_not_killed_by_app_deadline", | |
| 292 | 추가: "--nocapture", | |
| 293 | 추가: ]) | |
| 294 | 추가: .env(MODE, mode); | |
| 295 | 추가: if mode == "control" { | |
| 296 | 추가: command.env_remove("LD_PRELOAD"); | |
| 297 | 추가: } else { | |
| 298 | 추가: command.env("LD_PRELOAD", &clock); | |
| 299 | 추가: } | |
| 300 | 추가: let output = command.output().unwrap(); | |
| 301 | 추가: assert!( | |
| 302 | 추가: output.status.success(), | |
| 303 | 추가: "{mode}: {}\n{}", | |
| 304 | 추가: String::from_utf8_lossy(&output.stdout), | |
| 305 | 추가: String::from_utf8_lossy(&output.stderr) | |
| 306 | 추가: ); | |
| 307 | 추가: } | |
| 308 | 추가: } |
| @@ -0,0 +1,18 @@ | ||
| 1 | 추가: #define _GNU_SOURCE | |
| 2 | 추가: #include <dlfcn.h> | |
| 3 | 추가: #include <pthread.h> | |
| 4 | 추가: #include <string.h> | |
| 5 | 추가: #include <time.h> | |
| 6 | 추가: | |
| 7 | 추가: int clock_gettime(clockid_t id, struct timespec *value) { | |
| 8 | 추가: int (*original)(clockid_t, struct timespec *) = dlsym(RTLD_NEXT, "clock_gettime"); | |
| 9 | 추가: int result = original(id, value); | |
| 10 | 추가: char name[16] = {0}; | |
| 11 | 추가: pthread_getname_np(pthread_self(), name, sizeof(name)); | |
| 12 | 추가: if (result == 0 && id == CLOCK_MONOTONIC && !strcmp(name, "zipelo-worker-o")) { | |
| 13 | 추가: static _Thread_local time_t start; | |
| 14 | 추가: if (!start) start = value->tv_sec; | |
| 15 | 추가: if (value->tv_sec - start >= 2) value->tv_sec += 311; | |
| 16 | 추가: } | |
| 17 | 추가: return result; | |
| 18 | 추가: } |