Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13822] FileHandle closeOnDealloc is not respected #3241

Open
benlangmuir opened this issue Nov 3, 2020 · 5 comments
Open

[SR-13822] FileHandle closeOnDealloc is not respected #3241

benlangmuir opened this issue Nov 3, 2020 · 5 comments

Comments

@benlangmuir
Copy link
Member

Previous ID SR-13822
Radar None
Original Reporter @benlangmuir
Type Bug
Status Reopened
Resolution
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, Windows
Assignee None
Priority Medium

md5: 5eb42200be9afdbe9a126682aa13b90c

Issue Description:

In swift-corelibs-foundation, FileHandle(fileDescriptor: fd, closeOnDealloc: false) is calling `close()` when deinit runs. On Darwin, it correctly does not call `close()`.

Reproducer:

import Foundation
print("before")
var handle: FileHandle? = FileHandle(fileDescriptor: STDOUT_FILENO, closeOnDealloc: false)
handle = nil
print("after")

On Linux, this prints "before". On Darwin, it correctly prints "before\nafter"

@compnerd
Copy link
Collaborator

compnerd commented Nov 3, 2020

+@millenomi

@spevans
Copy link
Collaborator

spevans commented Nov 30, 2020

#2932

@spevans
Copy link
Collaborator

spevans commented Nov 30, 2020

With the fix:

ubuntu2004:~/swift-source $ ~/swift-build/toolchains/main-test/usr/bin/swift
Welcome to Swift version 5.3-dev (LLVM d6fb8423828a5e4, Swift 638d5e7be2d38c7).
Type :help for assistance.
  1> import Foundation 
  2. print("before") 
  3. var handle: FileHandle? = FileHandle(fileDescriptor: STDOUT_FILENO, closeOnDealloc: false) 
  4. handle = nil 
  5. print("after")
before
after
handle: FileHandle? = nil
  6>  

@benlangmuir
Copy link
Member Author

Looks good in

swift-DEVELOPMENT-SNAPSHOT-2020-12-14-a

@spevans
Copy link
Collaborator

spevans commented Dec 16, 2020

This fix breaks in Windows so #2944 has been opened to disable the functionality and tests, but only on Windows. It will still work on other platforms.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants