Unable to create issues or pull requests #10064

Closed
opened 2025-11-02 08:57:14 -06:00 by GiteaMirror · 7 comments
Owner

Originally created by @futurescenario9 on GitHub (Jan 5, 2023).

Description

It is not possible to create issues or pull requests, trying to do so results in http status 500.
Here is what I think is the relevant log:

2023/01/03 16:30:50 ...rs/web/repo/issue.go:1086:NewIssuePost() [I] [63b44a2a] [SQL] BEGIN TRANSACTION [] - 222.3µs
2023/01/03 16:30:50 ...vices/issue/issue.go:26:NewIssue() [I] [63b44a2a] [SQL] UPDATE issue_index SET max_index=max_index+1   WHERE group_id=? [1]
2023/01/03 16:30:50 ...vices/issue/issue.go:26:NewIssue() [I] [63b44a2a] [SQL] INSERT INTO issue_index (group_id, max_index) VALUES (?, 0) [1] - 509.6µs
2023/01/03 16:30:50 ...vices/issue/issue.go:26:NewIssue() [I] [63b44a2a] [SQL] UPDATE issue_index SET max_index=max_index+1 WHERE group_id=? [1] - 179.5µs
2023/01/03 16:30:50 ...rs/web/repo/issue.go:1086:NewIssuePost() [I] [63b44a2a] [SQL] ROLLBACK []
2023/01/03 16:05:37 ...rs/web/repo/issue.go:1091:NewIssuePost() [E] [63b44441] NewIssue: generate issue index failed: impossible error when GetNextResourceIndex, insert and update both succeeded but no record is updated

If I run these querys myself through the console, they work as expected and also return the right amount of rows affected (1) but when run by gitea it seems to always return 0.
f7ade6de7c/models/db/index.go (L98-L103)

The MSSQL version is 15.0.2095.3

Gitea Version

1.18

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

Windows 10

How are you running Gitea?

I'm using this binary: https://dl.gitea.io/gitea/1.18.0/gitea-1.18.0-windows-4.0-amd64.exe

Database

MSSQL

Originally created by @futurescenario9 on GitHub (Jan 5, 2023). ### Description It is not possible to create issues or pull requests, trying to do so results in http status 500. Here is what I think is the relevant log: ``` 2023/01/03 16:30:50 ...rs/web/repo/issue.go:1086:NewIssuePost() [I] [63b44a2a] [SQL] BEGIN TRANSACTION [] - 222.3µs 2023/01/03 16:30:50 ...vices/issue/issue.go:26:NewIssue() [I] [63b44a2a] [SQL] UPDATE issue_index SET max_index=max_index+1 WHERE group_id=? [1] 2023/01/03 16:30:50 ...vices/issue/issue.go:26:NewIssue() [I] [63b44a2a] [SQL] INSERT INTO issue_index (group_id, max_index) VALUES (?, 0) [1] - 509.6µs 2023/01/03 16:30:50 ...vices/issue/issue.go:26:NewIssue() [I] [63b44a2a] [SQL] UPDATE issue_index SET max_index=max_index+1 WHERE group_id=? [1] - 179.5µs 2023/01/03 16:30:50 ...rs/web/repo/issue.go:1086:NewIssuePost() [I] [63b44a2a] [SQL] ROLLBACK [] 2023/01/03 16:05:37 ...rs/web/repo/issue.go:1091:NewIssuePost() [E] [63b44441] NewIssue: generate issue index failed: impossible error when GetNextResourceIndex, insert and update both succeeded but no record is updated ``` If I run these querys myself through the console, they work as expected and also return the right amount of rows affected (1) but when run by gitea it seems to always return 0. https://github.com/go-gitea/gitea/blob/f7ade6de7c1c4991c650d6b96e6407053e6bdae7/models/db/index.go#L98-L103 The MSSQL version is `15.0.2095.3` ### Gitea Version 1.18 ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version _No response_ ### Operating System Windows 10 ### How are you running Gitea? I'm using this binary: https://dl.gitea.io/gitea/1.18.0/gitea-1.18.0-windows-4.0-amd64.exe ### Database MSSQL
GiteaMirror added the issue/needs-feedback label 2025-11-02 08:57:14 -06:00
Author
Owner

@wxiaoguang commented on GitHub (Jan 6, 2023):

Is it a one-time error, or it keeps reproducing?


If it keeps reproducing, could you show the content and structure of table issue_index ?

And another guess it that XORM's RowsAffected doesn't work well with MSSQL (well, pretty unlikely ....). In logs we can see UPDATE issue_index SET max_index=max_index+1 WHERE group_id=? [1], if the [1] means that one row has been updated, then the code should not go into the slow path.

@wxiaoguang commented on GitHub (Jan 6, 2023): Is it a one-time error, or it keeps reproducing? ---- If it keeps reproducing, could you show the content and structure of table `issue_index` ? And another guess it that XORM's `RowsAffected` doesn't work well with MSSQL (well, pretty unlikely ....). In logs we can see ` UPDATE issue_index SET max_index=max_index+1 WHERE group_id=? [1]`, if the `[1]` means that one row has been updated, then the code should not go into the slow path.
Author
Owner

@wxiaoguang commented on GitHub (Jan 6, 2023):

I can not reproduce your problem with this setup. MSSQL 2019 is 15.x

version: '3'

services:
  gitea:
    image: gitea/gitea:1.18.0
    volumes:
      - ./gitea-1.18-mssql:/data
    ports:
      - 3000:3000
      - 2222:22
    #restart: never

  sql-server-db:
    image: mcr.microsoft.com/mssql/server:2019-latest
    environment:
      SA_PASSWORD: "change_this_password"
      ACCEPT_EULA: "Y"
@wxiaoguang commented on GitHub (Jan 6, 2023): I can not reproduce your problem with this setup. MSSQL 2019 is 15.x ``` version: '3' services: gitea: image: gitea/gitea:1.18.0 volumes: - ./gitea-1.18-mssql:/data ports: - 3000:3000 - 2222:22 #restart: never sql-server-db: image: mcr.microsoft.com/mssql/server:2019-latest environment: SA_PASSWORD: "change_this_password" ACCEPT_EULA: "Y" ```
Author
Owner

@futurescenario9 commented on GitHub (Jan 9, 2023):

No, I assume the [1] is the parameter list which replaces the ? in the query, for example if I try to create an issue in the second repository, it says [2].
It always happens when I try to create either an issue or a pull request even if it's a different repository.

CREATE TABLE [dbo].[issue_index](
	[group_id] [bigint] NOT NULL,
	[max_index] [bigint] NULL,
PRIMARY KEY CLUSTERED 
(
	[group_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

The table was generated by 1.18.0-rc1 if that matters.
The table is currently empty, however I ran the queries manually after encountering the error, to see if there's an error in MSSQL itself, but as already mentioned, there were no apparent errors. Then I deleted the row again.
I'll try out your docker-compose example to see if I also don't get any error there.
EDIT:
In docker it works, I even tried it out with the exact same versions I used, so now I have no clue what the issue could be unless it's specific to Windows 10's binaries.
EDIT 2:
I wrote a small test program where I used the packages database/sql and github.com/denisenkom/go-mssqldb (I tried the fork by Microsoft too) which should be what xorm uses and while RowsAffected returns the actual number of rows affected with mssql in docker, my actual mssql server always returns 0. So this is either a configuration issue (any advice appreciated), an issue with mssql on windows and/or one of the aforementioned packages.

@futurescenario9 commented on GitHub (Jan 9, 2023): No, I assume the `[1]` is the parameter list which replaces the `?` in the query, for example if I try to create an issue in the second repository, it says `[2]`. It always happens when I try to create either an issue or a pull request even if it's a different repository. ``` CREATE TABLE [dbo].[issue_index]( [group_id] [bigint] NOT NULL, [max_index] [bigint] NULL, PRIMARY KEY CLUSTERED ( [group_id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] ``` The table was generated by 1.18.0-rc1 if that matters. The table is currently empty, however I ran the queries manually after encountering the error, to see if there's an error in MSSQL itself, but as already mentioned, there were no apparent errors. Then I deleted the row again. I'll try out your docker-compose example to see if I also don't get any error there. EDIT: In docker it works, I even tried it out with the exact same versions I used, so now I have no clue what the issue could be unless it's specific to Windows 10's binaries. EDIT 2: I wrote a small test program where I used the packages `database/sql` and `github.com/denisenkom/go-mssqldb` (I tried the fork by Microsoft too) which should be what xorm uses and while RowsAffected returns the actual number of rows affected with mssql in docker, my actual mssql server always returns 0. So this is either a configuration issue (any advice appreciated), an issue with mssql on windows and/or one of the aforementioned packages.
Author
Owner

@futurescenario9 commented on GitHub (Jan 10, 2023):

I found the problem, it actually was a configuration issue.
I had to run this query, it disables a connection option called "no count"

EXEC sys.sp_configure N'user options', N'0'
GO
RECONFIGURE WITH OVERRIDE
GO
@futurescenario9 commented on GitHub (Jan 10, 2023): I found the problem, it actually was a configuration issue. I had to run this query, it disables a connection option called "no count" ``` EXEC sys.sp_configure N'user options', N'0' GO RECONFIGURE WITH OVERRIDE GO ```
Author
Owner

@jolheiser commented on GitHub (Jan 10, 2023):

I wonder if this is worth having in the docs somewhere? In case someone else runs in to it.
I don't use MSSQL, so I'm not sure how common this connection option is or the usual defaults.

@jolheiser commented on GitHub (Jan 10, 2023): I wonder if this is worth having in the docs somewhere? In case someone else runs in to it. I don't use MSSQL, so I'm not sure how common this connection option is or the usual defaults.
Author
Owner

@wxiaoguang commented on GitHub (Jan 10, 2023):

Luckily, it's a client option, and it's only used for batched statements or stored procedures, it should only be used explicitly by a client.

Just like MySQL can have startup statements with a lot of SET xxx, if some users write incorrect SET xxx options, MySQL would also behave strangely. So, just do not do that if you are not sure what they are for. I do not think it's worth to be noted in document.

@wxiaoguang commented on GitHub (Jan 10, 2023): Luckily, it's a client option, and it's only used for batched statements or stored procedures, it should only be used explicitly by a client. Just like MySQL can have startup statements with a lot of `SET xxx`, if some users write incorrect `SET xxx` options, MySQL would also behave strangely. So, just do not do that if you are not sure what they are for. I do not think it's worth to be noted in document.
Author
Owner

@futurescenario9 commented on GitHub (Jan 17, 2023):

It's a bit annoying though because no matter what I set it breaks either application using that database.
It doesn't seem to be possible to just disable it for one user, it's enabled for all and I'd have to run SET NOCOUNT OFF/ON upon opening each connection.

@futurescenario9 commented on GitHub (Jan 17, 2023): It's a bit annoying though because no matter what I set it breaks either application using that database. It doesn't seem to be possible to just disable it for one user, it's enabled for all and I'd have to run `SET NOCOUNT OFF/ON` upon opening each connection.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#10064