# \#SendingRisksDataRace errors when turning on NonisolatedNonsendingByDefault

**URL:** <https://forums.swift.org/t/sendingrisksdatarace-errors-when-turning-on-nonisolatednonsendingbydefault/84589>\
**Category:** Using Swift\
**Tags:** asyncawait, sendable, nonisolated\
**Created:** [February 6, 2026, 12:07am UTC](https://forums.swift.org/t/sendingrisksdatarace-errors-when-turning-on-nonisolatednonsendingbydefault/84589 "2026-02-06T00:07:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cyberbeni](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cyberbeni/32/46241_2.png) [@Cyberbeni](https://forums.swift.org/u/Cyberbeni)\
**Post date:** [February 6, 2026, 12:07am UTC](https://forums.swift.org/t/sendingrisksdatarace-errors-when-turning-on-nonisolatednonsendingbydefault/84589/1 "2026-02-06T00:07:06Z")

</div>

I am using Swift 6.2.3 on Linux with `// swift-tools-version:6.2`. When I turn on `NonisolatedNonsendingByDefault` then the following code:

```swift
private extension HTML {
	consuming func render(into buffer: UnsafeMutablePointer<ByteBuffer>, chunkSize: Int) async throws {
		try await render(into: ByteBufferWriter(buffer: buffer), chunkSize: chunkSize)
	}
}

```

Produces 2 errors. One about sending self (Both this method and the method I'm calling are consuming), this one makes zero sense.  
Another about passing in the ByteBufferWriter that is getting initialized here, which might make sense if the initializer escaped self (which is not the case here, also using final class or struct makes no difference) but I haven't found any ways of marking the initializer's return value `sending Self`

And then this one:

```swift
extension ResponseBodyWriter {
	mutating func writeSSE(event: String? = nil, html: (any HTML)?) async throws {
		try await write(ByteBuffer.sse(event: event, html: html))
	}
}

```

Also produces an error about sending self. This one I can understand.

All of the errors get resolved by adding some `@concurrent` annotations. Is this the intended way for migrating to `NonisolatedNonsendingByDefault` or am I missing something?

As for the first 2 errors, can someone enlighten me?

---

<div class="post-metadata">

**Author:** ![Cyberbeni](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cyberbeni/32/46241_2.png) [@Cyberbeni](https://forums.swift.org/u/Cyberbeni)\
**Post date:** [February 6, 2026, 12:27am UTC](https://forums.swift.org/t/sendingrisksdatarace-errors-when-turning-on-nonisolatednonsendingbydefault/84589/2 "2026-02-06T00:27:45Z")

</div>

Wanted to test enabling this feature flag on the dependency where I am getting the errors.

Which resulted in finding out that this upcoming feature flag doesn't make local functions nonisolated(nonsending), so this code:

```swift
    @_unavailableInEmbedded
    static func _render<Renderer: _AsyncHTMLRendering>(
        _ html: consuming Self,
        into renderer: inout Renderer,
        with context: consuming _RenderingContext
    ) async throws {
        func render<H: HTML>(
            _ html: H,
            into renderer: inout some _AsyncHTMLRendering,
            with context: consuming _RenderingContext
        ) async throws {
            try await H._render(html, into: &renderer, with: context)
        }

        try await render(html.__body, into: &renderer, with: context)
    }

```

will fail because our nonisolated(nonsending) render is trying to call into the `@concurrent` local render function. I assume this is a bug and not intentional?

---

<div class="post-metadata">

**Author:** ![rayx](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rayx/32/12204_2.png) [@rayx](https://forums.swift.org/u/rayx)\
**Post date:** [February 6, 2026, 3:30am UTC](https://forums.swift.org/t/sendingrisksdatarace-errors-when-turning-on-nonisolatednonsendingbydefault/84589/3 "2026-02-06T03:30:29Z")

</div>

Just a few quick comments (I'm not familiar with the API in your example code).

> [@Cyberbeni](#):
>
> Produces 2 errors. One about sending self (Both this method and the method I'm calling are consuming), this one makes zero sense.

A `consuming` method doens't invalidate `self`. It's ok to continue accessing the instance using the same variable after calling it, because an implicity copy is made in this case. To invalidate a binding, you need to use `consume` operator. But even that won't work in your example because there might be multiple variable holding the same reference to a `HTML` instance.

In general I think ownership and concurrency were designed as two orthogonal features in Swift (though I didn't see discussion about it).

EDIT: I later realized that my above description was inaccurate. In my new understanding `consuming` modifer is more about value than binding. In practice, however, [my experiment](https://forums.swift.org/t/copy-operator-doesnt-clone-a-class-instance/84592) showed that after running a consuming method, a class instance is still shared. So my conclusion still holds.

> [@Cyberbeni](#):
>
> ... but I haven't found any ways of marking the initializer's return value `sending Self`

Are you trying to create an instance in isolation A and pass it to isolation B? If so, I think the idiomatic approach is to define its `init` as a nonisolated method (I haven't used it myself though).

> [@Cyberbeni](#):
>
> All of the errors get resolved by adding some `@concurrent` annotations. Is this the intended way for migrating to `NonisolatedNonsendingByDefault` or am I missing something?

Since all issues are introduced by `NonisolatedNonsendingByDefault` setting, they can be resolved by adding `@concurrent` annotations manually. I suppose what you really asked about was why the change caused the issues. Without understanding of your code, I suspect one possible reason is that nonisolated function's parameters are task isolated, they can be passed to global executors but not to actors (that's the difference caused by the setting).
