### Bug description

I'm not sure how much can be done about this, but some packages use `closeAllConnections()` internally and therefore kill the connection to the quarto renderer.

With this file:

````md
---
title: "test"
---

```{r}
closeAllConnections()
```

````

`quarto::quarto_preview()` produces a slightly more detailed error message than `quarto::quarto_render()` with:

```md
processing file: Untitled.qmd
  |...................................                 |  67% (unnamed-chunk-1)Quitting from lines 6-7 (Untitled.qmd) 
Error in isIncomplete(con) : invalid connection
Calls: .main ... evaluate_call -> handle_output -> <Anonymous> -> isIncomplete
Quitting from lines 6-7 (Untitled.qmd) 
Error in isOpen(con) : invalid connection
Calls: .main ... <Anonymous> -> evaluate_call -> <Anonymous> -> isOpen
                                                                                                            
Execution halted
Error in run_serve_daemon("preview", file, NULL, args, render, port, host,  : 
  Error starting quarto
```

## Details:
This appears to be cross platform, but my device info is as follows:
- OS: macOS 13.3 (22E252) (M1)
- RStudio:
```
RStudio 2023.03.0+386 "Cherry Blossom" Release (3c53477afb13ab959aeb5b34df1f10c237b256c3, 2023-03-09) for macOS
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2023.03.0+386 Chrome/108.0.5359.179 Electron/22.0.3 Safari/537.36
```
- R: 
```md
platform       aarch64-apple-darwin20      
arch           aarch64                     
os             darwin20                    
system         aarch64, darwin20           
status                                     
major          4                           
minor          2.2                         
year           2022                        
month          10                          
day            31                          
svn rev        83211                       
language       R                           
version.string R version 4.2.2 (2022-10-31)
nickname       Innocent and Trusting  
```
- Quarto: 
```md
quarto check

[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.1: OK
      Dart Sass version 1.55.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.3.326
      Path: /Applications/quarto/bin

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.10.1
      Path: /Library/Frameworks/Python.framework/Versions/3.10/bin/python3
      Jupyter: 4.10.0
      Kernels: julia-1.7, python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
      Version: 4.2.2
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library
      knitr: 1.42
      rmarkdown: 2.21

[✓] Checking Knitr engine render......OK
```

### Checklist

- [X] Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
- [X] Please [format your issue](https://quarto.org/bug-reports.html#formatting-make-githubs-markdown-work-for-us) so it is easier for us to read the bug report.
- [X] Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- [X] Please document the operating system you're running. If on Linux, please provide the specific distribution.
- [X] Please provide the output of `quarto check` so we know which version of quarto and its dependencies you're running.
cderv
2023-04-17T16:07:27Z
guslipkin
bug upstream knitr
closed
`closeAllConnections()` causes render and preview failure
https://github.com/quarto-dev/quarto-cli/issues/5214